1

I've used

chkBox.setIcon();
chkBox.setSelectedIcon();
chkBox.setDisabledIcon();
chkBox.setDisabledSelectedIcon();

to set custom icons for my JCheckbox. But now, if the focus moves to one of the checkboxes, there is no border shown around them or anything else, which tells that the checkbox has focus.

Does anyone know, how to give some feedback when a customized checkbox has focus?

Thanks

mKorbel
  • 109,525
  • 20
  • 134
  • 319
haferblues
  • 2,155
  • 4
  • 26
  • 39
  • can reproduce it in nimbus (where only the icon, not the text has a focus decoration). Looks like you have to do it yourself, not overly surprising when tweaking the defaults :-) Curious, why do you want custom icons? You might confuse your users .. – kleopatra Sep 24 '12 at 10:18

2 Answers2

2

Your problem definitely depends on Look and Feel (L&F) that you are using in your application (if you don't setup one - i guess you are using MetalLookAndFeel?).

Anyway, there might be a lot of solutions:

  1. Check that your JCheckBox is actually focusable and focus painted. Be aware that some L&F might switch off focus painting - check checkBox.setFocusPainted() method.

  2. If you are not satisfied with default focus painting - you might want to create your own CheckBoxUI that paints a better focus indicator. That requires some basic knowledge in UIs creation though.

  3. If you want to paint focus indication straight on the check icon itself you can create your own Icon-based implementation that paints it together with current check state. I have posted a custom Icon example in other topic about state-dependant icon if you want to see a real example.

There might be other solutions but they depends on the L&F you are using...

Community
  • 1
  • 1
Mikle Garin
  • 10,083
  • 37
  • 59
0

You can use this ready-to use checkbox alternative: http://codetoearn.blogspot.com/2013/01/swing-fantasy-checkbox-with-customized.html

ehsun7b
  • 4,796
  • 14
  • 59
  • 98