groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup() .addComponent(b1) .addGap(10) .addComponent(b2));
There are three ways to add gaps between two components. They are based on the gap size and their ability to resize.
- You can add a rigid gap between two components using the addGap(int gapSize).
- You can add a flexible (spring-like) gap between two components, which has a minimum, a preferred, and a maximum size, using the addGap(int min, int pref, int max) method. To add a flexible gap with 5, 10, and 50 as the minimum, preferred, and maximum size respectively, you set up your horizontal group like so: