I am trying to prune off unecessary pixels on an existing Java Swing UI. It uses GridbagConstrains mostly, but some other LayoutManagers too. A lot of the components are just added to containers and by default they’ll pad themselves with 10 extra pixels on each side. For example, with the GridBagConstrains, I have a checkBox that is padded with way too many pixels on each side by default. I set the ipadxy and insets to 0, but it had no effect. Can anyone offer some general tips?
Share
Your
JCheckBoxmay have a default border that pads the component out some. Try setting a zero-width empty border on the checkbox, I think that will help:Edit
For JPanels, make sure their layout manager is not adding padding. A common case is
new JPanel(). By default the layout for a JPanel is a BorderLayout with some horizontal and vertical gap. Instead, usenew JPanel(new BorderLayout())which still uses a border layout, but the horizontal and vertical gap will be zeroAlso, JPanels and JToolBars are both containers, keep in mind their children may have non-empty borders by default as well (for example, a JButton added to a JToolBar)