6

Does anyone know if there is an easy way to put a border around a JCheckBox object including the label? setBorder doesn't seem to have any effect. I know I could put each checkbox inside of a JPanel and border that, but is there no way to border the entire JCheckBox by itself? Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
f1wade
  • 2,877
  • 6
  • 27
  • 43

1 Answers1

10

on a jcheckbox the setborder does work, its just that the border is not painted. all you have to do is call setBorderPainted(true) and it should work.

f1wade
  • 2,877
  • 6
  • 27
  • 43
  • 1
    From javadoc for setBorder() "Although technically you can set the border on any object that inherits from JComponent, the look and feel implementation of many standard Swing components doesn't work well with user-set borders. In general, when you want to set a border on a standard Swing component other than JPanel or JLabel, we recommend that you put the component in a JPanel and set the border on the JPanel." – ka3ak Mar 13 '12 at 17:48
  • 1
    @ka3ak, still useful when coding/testing/debugging component layouts – ryvantage Sep 21 '14 at 23:29
  • 2
    Thank you. Geez, setBorderPainted? WTF Why? – Adam Hughes Mar 14 '16 at 17:04