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:
Get Beginning Java 8 APIs, Extensions and Libraries Swing, JavaFX, JavaScript, JDBC and Network Programming APIs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.