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?

Re: Clickable spot in Picture 80 80

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.

Re: Clickable spot in Picture 80 80

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.

Re: Clickable spot in Picture 80 80

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.