BoxLayout filler and gapper - Java Swing

Java examples for Swing:BoxLayout

Introduction

Box class can create invisible components and add them to a box to adjust spacing between two components.

Box class provides four types of invisible components:

  • Glue
  • Strut
  • Rigid Area
  • Filler

A glue is an invisible, expandable component.

import javax.swing.Box;
import javax.swing.JButton;

public class Main {
  public static void main(String[] argv) throws Exception {
    Box hBox = Box.createHorizontalBox();
    hBox.add(new JButton("First"));
    hBox.add(Box.createHorizontalGlue());
    hBox.add(new JButton("Last"));

  }
}

Related Tutorials