Hi :)

I was hoping someone could point me in the right direction to create a grid of clickable objects/images/shapes. My problem is this, I have to create a grid of 100+ characters that, when you click on one, appends a JTextArea with a specific, different, character. The only idea thus far I could come up with is creating a background image containing all of the characters, and then overlay that image with transparent buttons :$

It's a very long and ineffective way of doing it, so any help is appreciated :)

PS. I have not begun coding (this part), as I am not sure how to do it. I am not in any way asking for code as an answer, just a gentle push in the right direction :)

Thanx, that's perfect :)

One last thing, is it possible to draw with Graphics2D on a button?

I don't see why not. But don't do that. Just add an image, it is much easier.

I have to create a lot of unique symbols O.o To create an image for each of them would be extremely time consuming. I thought I'd draw the symbols with a loop :)

Edited 6 Years Ago by litchi: n/a

I suppose you could try to draw different sized rectangles and other shapes then. But that's where you're on your own as far as me helping you, because I've only drawn on JPanels before.

If drawing on the buttons proves to be too hard, you could also draw your grid on a JPanel, implement MouseListener, detect the user's button clicks (using MouseListener) and detect whether or not you clicked on a particular button. I wrote code once that did exactly that, but the project is on my other laptop. If it comes to it, I can grab the project and give you an example.

JLabels would work as well. I agree with BJSC, it would be a lot easier to draw an image one time in an editor for each symbol than to render them from primitive ops with Graphics2D.

If drawing on the buttons proves to be too hard, you could also draw your grid on a JPanel, implement MouseListener, detect the user's button clicks (using MouseListener) and detect whether or not you clicked on a particular button. I wrote code once that did exactly that, but the project is on my other laptop. If it comes to it, I can grab the project and give you an example.

This was exactly what I was looking for! Thank you. I'll draw the grid on a JLabel (done), and then add a MouseListener to get the coordinates :) Since all of the symbols (braille characters) are exactly the same size, this shouldn't be too difficult :)

Once again, thank you!

Edited 6 Years Ago by litchi: n/a

No problem. You might want to check out the contains() methods of the Rectangle class. They make it easier to detect which braille character you are clicking on.

Bingo! :D I just overcame the biggest hurdle of my program :) I dont know how to thank you enough :X

This question has already been answered. Start a new discussion instead.