Use BoxLayout rigid area - Java Swing

Java examples for Swing:BoxLayout

Introduction

A rigid area is an invisible component that is always the same size.

import java.awt.Dimension;

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"));
    // Add a 10x5 rigid area to a horizontal box
    hBox.add(Box.createRigidArea(new Dimension(10, 5)));

    hBox.add(new JButton("Last"));

  }
}

Related Tutorials