List of usage examples for javax.swing Box Box
public Box(int axis)
Box
that displays its components along the specified axis. From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component1 = new JButton(); Box box = new Box(BoxLayout.X_AXIS); int width = 10; box.add(Box.createHorizontalStrut(width)); box.add(component1);// w w w .j a v a2s . co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component1 = new JButton(); JButton component2 = new JButton(); Box box = new Box(BoxLayout.X_AXIS); box.add(component1);/*from w w w .jav a2 s . c o m*/ box.add(Box.createGlue()); box.add(component2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component1 = new JButton(); JButton component2 = new JButton(); Box box = new Box(BoxLayout.X_AXIS); box = Box.createHorizontalBox(); // Add components box.add(component1);// w w w .j a v a2 s . co m box.add(component2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component1 = new JButton(); JButton component2 = new JButton(); // Create vertical box container Box box = new Box(BoxLayout.Y_AXIS); // create a vertical box container box = Box.createVerticalBox(); // Add components box.add(component1);//from w ww . ja v a 2 s . co m box.add(component2); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = new Box(BoxLayout.Y_AXIS); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Component rowTwo = Box.createVerticalStrut(2); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);/*from w w w .j a va2 s . c o m*/ f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = new Box(BoxLayout.Y_AXIS); rowOne.add(new JLabel("Username")); rowOne.add(Box.createRigidArea(new Dimension(20, 20))); rowOne.add(new JTextField()); Component rowTwo = Box.createVerticalStrut(2); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);//from w w w. j a va2 s . c o m f.setVisible(true); }
From source file:Main.java
public static Box createBox(int axis, Component... comps) { Box r = new Box(axis); for (Component comp : comps) { r.add(comp);/* w w w.j a va 2 s . c o m*/ } return r; }
From source file:Main.java
public Main() { Box box = new Box(BoxLayout.Y_AXIS); add(box);/*from ww w . j a va 2 s . com*/ JLabel label = new JLabel("I'm centered"); label.setAlignmentX(JComponent.CENTER_ALIGNMENT); box.add(Box.createVerticalGlue()); box.add(label); box.add(Box.createVerticalGlue()); }
From source file:MainClass.java
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);/* w w w . j a v a 2 s .co m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); }
From source file:Main.java
public Main(int axis) { super(BoxLayout.Y_AXIS); container = new Box(axis); container.setAlignmentX(Box.LEFT_ALIGNMENT); add(container);/*from w w w . j a v a 2s.c o m*/ JTextArea text = new JTextArea(); container.add(new JScrollPane(text)); JButton split = new JButton("Split"); split.setAlignmentX(Box.LEFT_ALIGNMENT); split.addActionListener(e -> { JTextArea t = new JTextArea(); container.add(new JScrollPane(t)); revalidate(); }); add(split); JButton axisChanger = new JButton("Change Axis"); axisChanger.setAlignmentX(Box.LEFT_ALIGNMENT); axisChanger.addActionListener(e -> { Box newContainer; if (((BoxLayout) container.getLayout()).getAxis() == BoxLayout.X_AXIS) { newContainer = Box.createVerticalBox(); } else { newContainer = Box.createHorizontalBox(); } for (Component c : container.getComponents()) { container.remove(c); newContainer.add(c); } remove(container); add(newContainer, 0); container = newContainer; container.setAlignmentX(Box.LEFT_ALIGNMENT); revalidate(); }); add(axisChanger); }