Example usage for javax.swing Box createVerticalBox

List of usage examples for javax.swing Box createVerticalBox

Introduction

In this page you can find the example usage for javax.swing Box createVerticalBox.

Prototype

public static Box createVerticalBox() 

Source Link

Document

Creates a Box that displays its components from top to bottom.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    Box b = Box.createVerticalBox();

    JTextField field1 = new JTextField();
    JTextField field2 = new JTextField();
    field1.setMaximumSize(new Dimension(Integer.MAX_VALUE, field1.getPreferredSize().height));
    field2.setMaximumSize(new Dimension(Integer.MAX_VALUE, field2.getPreferredSize().height));
    b.add(field1);//from w  ww  . j  a  v a2  s . c  om
    b.add(field2);

    b.add(Box.createVerticalGlue());

    f.setContentPane(b);
    f.setSize(500, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Box box = Box.createVerticalBox();
    for (int i = 1; i < 4; i++) {
        JPanel panel = new JPanel() {
            @Override//from ww w .ja v a 2 s .  co  m
            public Dimension getMaximumSize() {
                return getPreferredSize();
            }
        };
        JLabel label1 = new JLabel("Label");
        JLabel label2 = new JLabel(String.valueOf(i));
        panel.add(label1);
        panel.add(label2);
        box.add(panel);

    }

    JFrame frame = new JFrame();
    frame.add(box);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    Box box = Box.createVerticalBox();
    for (int i = 0; i < 100; i++) {
        box.add(new JLabel("Hello!"));
    }/*w w  w .  j a  v a  2s  .c  om*/
    panel.add(box);

    JTabbedPane tab = new JTabbedPane();
    JScrollPane scroll = new JScrollPane(panel);
    scroll.setPreferredSize(new Dimension(300, 300));
    tab.add(scroll, "Panel 1");

    JOptionPane.showMessageDialog(null, tab, "Test Tabbed", JOptionPane.PLAIN_MESSAGE);
}

From source file:BoxSample.java

public static void main(String args[]) {
    JFrame verticalFrame = new JFrame("Vertical");
    verticalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box verticalBox = Box.createVerticalBox();
    verticalBox.add(new JLabel("Top"));
    verticalBox.add(new JTextField("Middle"));
    verticalBox.add(new JButton("Bottom"));
    verticalFrame.add(verticalBox, BorderLayout.CENTER);
    verticalFrame.setSize(150, 150);//from  w  ww  . j  a v a  2 s  . c  om
    verticalFrame.setVisible(true);

}

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  w  w.j a v a  2s .  c o  m*/
    box.add(component2);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Box form = Box.createVerticalBox();
    form.add(new JLabel("Name:"));
    form.add(new JTextField("User Name"));

    form.add(new JLabel("Birthday:"));
    JFormattedTextField birthdayField = new JFormattedTextField(new SimpleDateFormat("MM/dd/yy"));
    birthdayField.setValue(new Date());
    form.add(birthdayField);//from w w w.  ja v  a 2s .  com

    form.add(new JLabel("Age:"));
    form.add(new JFormattedTextField(new Integer(32)));

    form.add(new JLabel("Hairs on Body:"));
    JFormattedTextField hairsField = new JFormattedTextField(new DecimalFormat("###,###"));
    hairsField.setValue(new Integer(100000));
    form.add(hairsField);

    form.add(new JLabel("Phone Number:"));
    JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("(###)###-####"));
    phoneField.setValue("(314)888-1234");
    form.add(phoneField);

    JFrame frame = new JFrame("User Information");
    frame.getContentPane().add(form);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:TryBoxLayout.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Box Layout");
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Create left column of radio buttons
    Box left = Box.createVerticalBox();
    ButtonGroup radioGroup = new ButtonGroup();
    JRadioButton rbutton;// w  ww. j a v a2 s  .c om
    radioGroup.add(rbutton = new JRadioButton("Red"));
    left.add(rbutton);
    radioGroup.add(rbutton = new JRadioButton("Green"));
    left.add(rbutton);
    radioGroup.add(rbutton = new JRadioButton("Blue"));
    left.add(rbutton);
    radioGroup.add(rbutton = new JRadioButton("Yellow"));
    left.add(rbutton);
    Box right = Box.createVerticalBox();
    right.add(new JCheckBox("A"));
    right.add(new JCheckBox("B"));
    right.add(new JCheckBox("C"));
    Box top = Box.createHorizontalBox();
    top.add(left);
    top.add(right);
    Container content = aWindow.getContentPane();
    content.setLayout(new BorderLayout());
    content.add(top, BorderLayout.CENTER);
    aWindow.pack();
    aWindow.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Box left = Box.createVerticalBox();
    left.add(Box.createVerticalStrut(30));
    ButtonGroup radioGroup = new ButtonGroup();
    JRadioButton rbutton;// w w w  .j av  a  2  s.c om
    radioGroup.add(rbutton = new JRadioButton("Red"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Green"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Blue"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Yellow"));
    left.add(rbutton);

    left.add(Box.createGlue());

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(left, BorderLayout.CENTER);

    Box right = Box.createVerticalBox();
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Dashed"));
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Thick"));
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Rounded"));

    right.add(Box.createGlue());

    JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.add(right, BorderLayout.CENTER);

    Box top = Box.createHorizontalBox();
    top.add(leftPanel);
    top.add(Box.createHorizontalStrut(5));
    top.add(rightPanel);

    Container content = aWindow.getContentPane();
    content.setLayout(new BorderLayout());
    content.add(top, BorderLayout.CENTER);

    BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS);

    content.setLayout(box);
    content.add(top);

    aWindow.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Box Layout");
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Box left = Box.createVerticalBox();
    left.add(Box.createVerticalStrut(30));
    ButtonGroup radioGroup = new ButtonGroup();
    JRadioButton rbutton;/*  ww w .  j a  v a2  s .  co m*/
    radioGroup.add(rbutton = new JRadioButton("Red"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Green"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Blue"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Yellow"));
    left.add(rbutton);

    left.add(Box.createGlue());

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Color"));
    leftPanel.add(left, BorderLayout.CENTER);

    Box right = Box.createVerticalBox();
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Dashed"));
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Thick"));
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Rounded"));

    right.add(Box.createGlue());

    JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Properties"));
    rightPanel.add(right, BorderLayout.CENTER);

    Box top = Box.createHorizontalBox();
    top.add(leftPanel);
    top.add(Box.createHorizontalStrut(5));
    top.add(rightPanel);

    Container content = aWindow.getContentPane();
    content.setLayout(new BorderLayout());
    content.add(top, BorderLayout.CENTER);

    BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS);

    content.setLayout(box);
    content.add(top);

    aWindow.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.setSize(240, 250);/*from w ww.  ja v a  2s.  c  o  m*/
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JScrollPane jscrlpLabel = new JScrollPane(
            new JLabel("<html>A<br>B<br>C<br>D<br>E<br>F<br>G<br>H<br></html>."));

    jscrlpLabel.setPreferredSize(new Dimension(200, 100));

    JLabel label = new JLabel("Option");
    JCheckBox a = new JCheckBox("A");
    JCheckBox b = new JCheckBox("B");
    JCheckBox c = new JCheckBox("C");
    JCheckBox d = new JCheckBox("D");
    JCheckBox e = new JCheckBox("E");

    Box box = Box.createVerticalBox();

    box.add(label);
    box.add(a);
    box.add(b);
    box.add(c);
    box.add(d);
    box.add(e);

    JScrollPane jscrlpBox = new JScrollPane(box);
    jscrlpBox.setPreferredSize(new Dimension(140, 90));
    f.add(jscrlpLabel);
    f.add(jscrlpBox);

    f.setVisible(true);
}