new Box(BoxLayout.Y_AXIS) : Box « Swing « Java Tutorial






import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.JTextField;

public class MainClass extends JFrame {

  public MainClass() {
    Box box = new Box(BoxLayout.Y_AXIS);
    box.add(new JButton("Test button"));
    box.add(new JSlider());
    box.add(new JTextField("Text field with some text", 20));
    box.add(new JButton("Another, bigger button"));

    getContentPane().add(box);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
  }

  public static void main(String[] args) {
    MainClass ex2 = new MainClass();
    ex2.setVisible(true);
  }
}








14.88.Box
14.88.1.Box simplifies working with BoxLayoutBox simplifies working with BoxLayout
14.88.2.new Box(BoxLayout.Y_AXIS)
14.88.3.Working with Box.Filler: Glue and Strut
14.88.4.Creating Rigid Areas: StrutCreating Rigid Areas: Strut
14.88.5.Box.createVerticalGlue()Box.createVerticalGlue()