Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using icons with JCheckBox

I have a swing application in which I want to use a JCheckbox with an icon. I constructed the icon as follows:

   JCheckBox unsubmit = new JCheckBox("Unsubmit",applet.undo);

When I do this, the label and the icon appear in my GUI but the box itself is no where to be found. If I construct the JCheckBox without the icon, the box comes back. I've tried adjusting the buttons's preferred size but it had no effect.

Anyone know what's going on here?

Thanks,

Elliott

like image 527
Elliott Avatar asked Jul 25 '12 19:07

Elliott


People also ask

How do I know if JCheckBox is checked?

A checkmark will be used to choose a box. JCheckBox often uses the methods isSelected and setSelected. To select, or un-select, a box, use the setSelected(boolean) method. To check if a box is selected, use the isSelected() method.

Which constructor is used to set the only image on JCheckBox?

JCheckBox is an implementation to checkbox . JCheckBox inherits JToggleButton class. Constructor of the class are : JCheckBox() : creates a new checkbox with no text or icon.


1 Answers

The Icon is being used in place of the box. Consider creating a JCheckBox and a JLabel placed immediately next to each other, and have the JLabel hold the ImageIcon.

like image 137
Hovercraft Full Of Eels Avatar answered Oct 13 '22 05:10

Hovercraft Full Of Eels