0

Possible Duplicate:
Add a complex image in the panel, with buttons around it in one customized user interface

I am creating an application which takes an image and imposes grid like look on the image (refer to Split image into clickable regions)

Now my question is how to make this image(after grid has been imposed) clickable.

[in other words the individual sub-parts of the image after applying grid have to be made CLICKABLE BUTTONS].

Community
  • 1
  • 1

1 Answers1

4

It is not clear what you mean by "Clickable Buttons"

If you want to have real buttons with images inside, then instead of JLabel create JButton:

buttons[i] = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(imgs[i].getSource())));
frame.getContentPane().add(labels[i]);

and then add ActionListener overriding actionPerformed()

If you want it to be labels, but clickable then add MouseListener to each JLabel overriding mousePressed or mouseClicked depending on desired behavior.

Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
  • Buttons can be 'plain'. See [this answer](http://stackoverflow.com/a/10862262/418556) for an example. – Andrew Thompson Jan 10 '13 at 14:59
  • thanks NIKOLAY..but can you specify more on that...ypu know i'm not a PRO on that stuffs...thanks again...!!! – Akash Tripathi Jan 10 '13 at 15:01
  • @user1967018, this website is for asking and answering specific questions with showing your effort and issues you are facing. – Nikolay Kuznetsov Jan 10 '13 at 15:03
  • Just noticed. `frame.getContentPane().add(labels[i]);` If the frame uses default layout, only the first (or last - I forget) of those components will appear. +1 for your answer, BTW. – Andrew Thompson Jan 10 '13 at 15:06
  • *"i didnt get you"* I would have said. "Show some effort and we might help more." Do you understand that? – Andrew Thompson Jan 10 '13 at 15:07
  • got you...n again thanks,soon i'll be back with more on that..!! – Akash Tripathi Jan 10 '13 at 15:11
  • @user1967018, welcome. In next question specify what exactly you are trying to achieve and your current related code. You might want to accept the answer with a green tick. – Nikolay Kuznetsov Jan 10 '13 at 15:13
  • thanks to all..that has worked. but the button image needs to be stretched to the entire area/span of the button AND,AND needs to be highlighted every time the mouse pointer is hovered upon the buttons. is it possible? – Akash Tripathi Jan 11 '13 at 12:13