Example usage for javax.swing BoxLayout Y_AXIS

List of usage examples for javax.swing BoxLayout Y_AXIS

Introduction

In this page you can find the example usage for javax.swing BoxLayout Y_AXIS.

Prototype

int Y_AXIS

To view the source code for javax.swing BoxLayout Y_AXIS.

Click Source Link

Document

Specifies that components should be laid out top to bottom.

Usage

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   ww  w. j  a  v  a2s.  co m*/
    box.add(component2);
}

From source file:TwoButtons.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JPanel basic = new JPanel();
    basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
    f.add(basic);//w  w  w  .j  a v a  2  s . c om

    basic.add(Box.createVerticalGlue());

    JPanel bottom = new JPanel();
    bottom.setAlignmentX(1f);
    bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));

    JButton ok = new JButton("OK");
    JButton close = new JButton("Close");

    bottom.add(ok);
    bottom.add(Box.createRigidArea(new Dimension(5, 0)));
    bottom.add(close);
    bottom.add(Box.createRigidArea(new Dimension(15, 0)));

    basic.add(bottom);
    basic.add(Box.createRigidArea(new Dimension(0, 15)));

    f.setSize(300, 250);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    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(new JTextField());
    Component rowTwo = Box.createVerticalStrut(2);

    f.add(rowOne, BorderLayout.NORTH);
    f.add(rowTwo, BorderLayout.SOUTH);
    f.setSize(300, 200);//from   ww  w. j  a va 2s.  c o  m
    f.setVisible(true);
}

From source file:RigidArea.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(new EmptyBorder(new Insets(40, 60, 40, 60)));

    panel.add(new JButton("Button"));
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(new JButton("Button"));
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(new JButton("Button"));
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(new JButton("Button"));

    JFrame f = new JFrame();
    f.add(panel);/*from   ww w  .  j a v a 2  s .  c o  m*/
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:BoxLayoutYAXISTest.java

public static void main(String[] args) {
    JFrame f = new JFrame("Vertical BoxLayout-managed container");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    for (float align = 0.0f; align <= 1.0f; align += 0.25f) {
        JButton button = new JButton("X Alignment = " + align);
        button.setAlignmentX(align);/*from   ww  w.j  a  va 2s.  co  m*/
        pane.add(button);
    }
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("This is BOX LAYOUT");
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
    panel1.setBackground(Color.yellow);

    JPanel panel2 = new JPanel();
    panel2.setLayout(new FlowLayout());
    panel2.setBackground(Color.ORANGE);

    for (int i = 0; i < 5; i++)
        panel1.add(new JCheckBox("CheckBox " + (i + 1)));

    f.add(panel1, BorderLayout.WEST);
    f.add(panel2, BorderLayout.CENTER);
    f.setVisible(true);//  w  w w . j a v  a  2 s .c  o  m
    f.setSize(300, 300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

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 v  a2s. c o m
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));

    JPanel a = new JPanel();
    a.setAlignmentX(Component.CENTER_ALIGNMENT);
    a.setPreferredSize(new Dimension(100, 100));
    a.setMaximumSize(new Dimension(100, 100)); // set max = pref
    a.setBorder(BorderFactory.createTitledBorder("aa"));
    JPanel b = new JPanel();
    b.setAlignmentX(Component.CENTER_ALIGNMENT);
    b.setPreferredSize(new Dimension(50, 50));
    b.setMaximumSize(new Dimension(50, 50)); // set max = pref
    b.setBorder(BorderFactory.createTitledBorder("bb"));

    frame.getContentPane().add(a);//  ww  w  . j av  a2 s. c  o  m
    frame.getContentPane().add(b);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    System.out.println(layout.preferredLayoutSize(container));
    container.setLayout(layout);//from ww w . jav  a  2 s  . co  m

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    System.out.println(layout.getLayoutAlignmentY(container));
    container.setLayout(layout);//from  w  w w . j  a va2  s  .  c  om

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}