I have three Java JCheckboxes
in a column, arranged by setting the layout of the container JPanel
to GridLayout(3, 1, 1, 1)
. When I run the program, there is too much vertical space between the JCheckBoxes; it looks like more than 1 pixel. Since I've already set the vertical space between the JCheckboxes in the layout to be 1 pixel, how else can I reduce the vertical space between these JCheckboxes?
Thanks.
I explored using
GridLayout
,BorderLayout
, andGridBagLayout
and I believe that any extra vertical space that is present in your application is due to the sizing of the JCheckBox component, not related to the layout manager. All of the examples below have no space between components in the layout manager.GridLayout
GridBagLayout
BorderLayout
Thank you Steve and Alex. Both your responses were correct. By setting the border to an empty border, I was able to move the checkboxes closer.
Does it help if you set the checkbox's border?
It may also be due to the Look & Feel's UI delegate's rendering. You typically have little control over this.