Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display and select Images in JApplet

 
anusha das
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I want to display around 10 images in a JApplet and let the user select some of them for further actions like rotation. I am using JLabels inside a JPanel to display the images. But how do I let the user select(highlight the image) and deselect multiple images using Ctrl+Click?

Any suggestions please....

Thanks
Anusha
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Handling control-clicks is just a matter of attaching a MouseListener, and checking whether the control key is down during the click.

The highlighting could be done by setting (or removing) a LineBorder for that JLabel.
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by anusha das:
I want to display around 10 images in a JApplet and let the user select some of them for further actions like rotation. I am using JLabels inside a JPanel to display the images. But how do I let the user select(highlight the image) and deselect multiple images using Ctrl+Click?


You can use JButton (or JToggleButton or JRadioButton) instead of JLabel. You can create them with an Icon and no text, just like JLabel. And there are methods that you can call to give them a less buttonlike appearance:

b.setFocusPainted(false);
b.setBorderPainted(false);
b.setContentAreaFilled(false);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic