Java Box create rigid area

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;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame("FlowLayout Nesting");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Box hBox = Box.createHorizontalBox();
    hBox.add(new JButton("First"));
    //from   w ww. ja  v a2 s . com
 // Add a 10x5 rigid area to a horizontal box 
    hBox.add(Box.createRigidArea(new Dimension(10, 5))); 
    hBox.add(new JButton("Last"));
    // Add JPanel to the content pane
    frame.getContentPane().add(hBox);

    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related