Using icons with JCheckBox
Asked Answered
M

1

8

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

Mundell answered 25/7, 2012 at 19:49 Comment(1)
Please include an sscce demonstrating the problem.Generic
P
13

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.

Perfection answered 25/7, 2012 at 19:51 Comment(1)
Or use JToggleButton with proper icons for selected and default.Circinate

© 2022 - 2024 — McMap. All rights reserved.