A BoxLayout Using the Box Class and Glue - Java Swing

Java examples for Swing:BoxLayout

Description

A BoxLayout Using the Box Class and Glue

Demo Code

import java.awt.BorderLayout;
import java.awt.Container;

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("BoxLayout with Glue");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = frame.getContentPane();
    Box hBox = Box.createHorizontalBox();
    hBox.add(new JButton("<<First"));
    hBox.add(new JButton("<Previous"));
    hBox.add(Box.createHorizontalGlue());
    hBox.add(new JButton("Next>"));
    hBox.add(new JButton("Last>>"));

    contentPane.add(hBox, BorderLayout.SOUTH);
    frame.pack();/* w  w w .j  av  a2s. c o  m*/
    frame.setVisible(true);
  }
}

Related Tutorials