0

Hello everyone.

I have successfully added an image to my JPanel, but what I want to do is this: I want to be able to mark a section of the image as clickable. Then when the user clicks within that section, I run some action. So essential I want to give the feel of a button and action Listener. Any suggestions please?

2
Contributors
3
Replies
15
Views
4 Years
Discussion Span
Last Post by sirlink99
0

Some information to add:

The Image I am using as the background image is larger than the JFrame it is in, I need it to be like that however. So the clickable area that I seek must stay locked to the picture and not the frame.

I'm still messing around with possible ways.

0

I have successfully added some invisible JPanel's to the areas. It seems that it is only by chance that these lined up. I fiddled for a bit, then it worked. Would it be advisable to then add some MouseListener's to these JPanel's?

And is there a better way to make areas in a picture clickable? Not a picture with pictures on it, just regions in a solid picture.

2

If you want to use graphics, then just use a Rectangle over the area that you want to be clickable. Then when you press the mouse button check the coordinates of the Mouse and it the Rectangle contains them. If they do then run the action. If the Image is in a JScrollPane this becomes more difficult.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.