How to reduce the space between 3 rotary flags?

I want to reduce the size between the components in the format group (on the left of the image). How to do it?

enter image description here

JPanel formattingGroup = createGroupWithName("Formatting"); formattingGroup.setMinimumSize(new Dimension(250, 20)); formattingGroup.setLayout(new GridLayout(5, 0)); add(formattingGroup); final JCheckBox showSurface = new JCheckBox("Show surface"); showSurface.setSelected(true); formattingGroup.add(showSurface); final JCheckBox showTerrain = new JCheckBox("Show terrain"); showTerrain.setSelected(true); formattingGroup.add(showTerrain); final JCheckBox showVehicleStatus = new JCheckBox("Show vehicle status"); showVehicleStatus.setSelected(true); formattingGroup.add(showVehicleStatus); JPanel pnl = createGroupWithName("Depth Stretch"); formattingGroup.add(pnl); JSlider slider = new JSlider(0, 10); pnl.add(slider); 
+4
source share
3 answers

When using GridLayout, all components are the same size.

You add JPanel with TitledBorder and JSlider to the grid. Therefore, the flags will have the same vertical height as this panel.

You need to use a different layout manager for the panel. Possibly a vertical BoxLayout.

+3
source

You can see the available size options described in Resizing a component .

+2
source

Use gridbaglayout because it gives you the ability to assign weights, columns, or rows and specify distance and fill values.

I created a Swing application that contains 12 frames, and they are all made using GridBagLayout.

I also tried others before, but they all had limitations. What is where GridBagLayout kicks. It's a little harder to start understanding how this works, but once you feel it, it's really best to get the components where you want.

If you want, I will give you a cool example of a frame created using GridBagLayout.

0
source

Source: https://habr.com/ru/post/1391556/


All Articles