Example usage for javax.swing Box createVerticalGlue

List of usage examples for javax.swing Box createVerticalGlue

Introduction

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

Prototype

public static Component createVerticalGlue() 

Source Link

Document

Creates a vertical glue component.

Usage

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);//from  ww  w.  j  ava 2  s .co  m

    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[] argv) {
    JFrame f = new JFrame();
    f.setLayout(new BorderLayout());

    JPanel panel = new JPanel();
    JButton button = new JButton("A-ha!");
    button.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.add(Box.createVerticalGlue());
    panel.add(button);/*from  ww w  .  j a va 2s . co m*/
    panel.add(Box.createVerticalGlue());

    f.getContentPane().add(panel);

    f.setVisible(true);
}

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);// w ww .jav a 2 s  .c  o m
    b.add(field2);

    b.add(Box.createVerticalGlue());

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

From source file:BoxLayoutVerticalGlueTest.java

public static void main(String[] args) {
    JFrame f = new JFrame("Vertical BoxLayout-managed container");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = new BoxPanel();
    f.setContentPane(pane);//from www.  j  a  va 2  s  .  c o m
    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);
        pane.add(button);
        pane.add(Box.createVerticalGlue());
    }
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:BoxLayoutDemo.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    p.add(createComponent("Component 1"));
    p.add(Box.createVerticalGlue());
    p.add(createComponent("Component 2"));
    p.add(createComponent("Component 3"));
    p.add(createComponent("Component 4"));
    frame.setContentPane(p);//from   w  ww.j  a v a2  s.  co m

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    Box box = new Box(BoxLayout.Y_AXIS);
    add(box);//from  w  ww. ja v  a  2s.  c om

    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:Main.java

public void init() {
    Box bv = Box.createVerticalBox();
    bv.add(new JLabel("Hello"));
    bv.add(Box.createVerticalGlue());
    bv.add(new JLabel("Applet"));
    bv.add(Box.createVerticalGlue());
    bv.add(new JLabel("World"));
    Box bh = Box.createHorizontalBox();
    bh.add(new JLabel("Hello"));
    bh.add(Box.createHorizontalGlue());
    bh.add(new JLabel("Applet"));
    bh.add(Box.createHorizontalGlue());
    bh.add(new JLabel("World"));
    bv.add(Box.createVerticalGlue());
    bv.add(bh);//from  w  w  w .j  av a  2s .c o  m
    bv.add(Box.createVerticalGlue());
    getContentPane().add(bv);
}

From source file:Main.java

public void createUI() {
    JPanel borderPanel = new JPanel(new BorderLayout());

    JLabel northLabel = new JLabel("Nawth");
    borderPanel.add(northLabel, BorderLayout.NORTH);

    JComboBox southCombo = new JComboBox();
    borderPanel.add(southCombo, BorderLayout.SOUTH);

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));

    JComboBox firstCombo = new JComboBox();
    centerPanel.add(firstCombo);//from  w  w  w  .ja v  a2 s. c  om
    centerPanel.add(Box.createVerticalGlue());
    JPanel centerPanelConstrain = new JPanel(new GridBagLayout());
    centerPanelConstrain.add(centerPanel);
    borderPanel.add(centerPanelConstrain, BorderLayout.CENTER);

    getContentPane().add(borderPanel);
    pack();
}

From source file:QandE.Layout3.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./*w  w  w .  ja v a  2  s . c o m*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Layout3");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Add the innards.
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    p.add(createComponent("Component 1"));
    p.add(Box.createVerticalGlue());
    p.add(createComponent("Component 2"));
    p.add(createComponent("Component 3"));
    p.add(createComponent("Component 4"));
    frame.setContentPane(p);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:SysConfig.java

public SysConfig() {
    super("JTabbedPane & BoxLayout Demonstration");
    setSize(500, 300);/*from  w w  w.ja va2s.c om*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel configPane = new JPanel();
    configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS));
    JTextArea question = new JTextArea("Which of the following options\n" + "do you have installed?");
    // Ok, now configure the textarea to show up properly inside the box.
    // This is part of the "high art" of Swing...
    question.setEditable(false);
    question.setMaximumSize(new Dimension(300, 50));
    question.setAlignmentX(0.0f);
    question.setBackground(configPane.getBackground());

    JCheckBox audioCB = new JCheckBox("Sound Card", true);
    JCheckBox nicCB = new JCheckBox("Ethernet Card", true);
    JCheckBox tvCB = new JCheckBox("Video Out", false);

    configPane.add(Box.createVerticalGlue());
    configPane.add(question);
    configPane.add(audioCB);
    configPane.add(nicCB);
    configPane.add(tvCB);
    configPane.add(Box.createVerticalGlue());

    JLabel audioPane = new JLabel("Audio stuff");
    JLabel nicPane = new JLabel("Networking stuff");
    JLabel tvPane = new JLabel("Video stuff");
    JLabel helpPane = new JLabel("Help information");

    audioCB.addItemListener(new TabManager(audioPane));
    nicCB.addItemListener(new TabManager(nicPane));
    tvCB.addItemListener(new TabManager(tvPane));

    config.addTab("System", null, configPane, "Choose Installed Options");
    config.addTab("Audio", null, audioPane, "Audio system configuration");
    config.addTab("Networking", null, nicPane, "Networking configuration");
    config.addTab("Video", null, tvPane, "Video system configuration");
    config.addTab("Help", null, helpPane, "How Do I...");

    getContentPane().add(config, BorderLayout.CENTER);
}