Example usage for javax.swing Box createHorizontalGlue

List of usage examples for javax.swing Box createHorizontalGlue

Introduction

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

Prototype

public static Component createHorizontalGlue() 

Source Link

Document

Creates a horizontal glue component.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box rowOne = Box.createHorizontalBox();
    rowOne.add(new JLabel("Username"));
    rowOne.add(new JTextField());
    Component rowTwo = Box.createHorizontalGlue();

    f.add(rowOne, BorderLayout.NORTH);
    f.add(rowTwo, BorderLayout.SOUTH);
    f.setSize(300, 200);/*from w  w  w  . j  a v a 2s  .  co  m*/
    f.setVisible(true);
}

From source file:Main.java

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

    Container contentPane = frame.getContentPane();
    Box hBox = Box.createHorizontalBox();
    hBox.add(new JButton("First"));
    hBox.add(new JButton("Previous"));
    hBox.add(Box.createHorizontalGlue());
    hBox.add(new JButton("Next"));
    hBox.add(new JButton("Last"));

    contentPane.add(hBox, BorderLayout.SOUTH);
    frame.pack();/*from  w  w w .  j av a 2  s  .  co m*/
    frame.setVisible(true);
}

From source file:MenuSample.java

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

    JMenuBar bar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    bar.add(fileMenu);// w  w w  .  ja  v a2  s .co m

    // Edit Menu, E - Mnemonic
    JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic(KeyEvent.VK_E);
    bar.add(editMenu);

    // Move help menu to right side
    bar.add(Box.createHorizontalGlue());

    // Help Menu, H - Mnemonic
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    bar.add(helpMenu);

    frame.setJMenuBar(bar);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Places the given components in a horizontal Box with a glue at the front,
 * causing the components to align right.
 * @param components the components to add
 * @return the components in a horizontal box, aligned right
 *///  www.jav  a  2s  . co  m
public static Box buildRightAlignedRow(Component... components) {
    final Box result = Box.createHorizontalBox();
    result.add(Box.createHorizontalGlue());
    Arrays.stream(components).forEach(result::add);
    return result;
}

From source file:Main.java

/**
 * Places the given components in a horizontal Box with a glue at the end,
 * causing the components to align left.
 * @param components the components to add
 * @return the components in a horizontal Box, aligned left
 *//*from ww  w.j a  v a 2s  .  co m*/
public static Box buildLeftAlignedRow(Component... components) {
    final Box result = Box.createHorizontalBox();
    Arrays.stream(components).forEach(result::add);
    result.add(Box.createHorizontalGlue());
    return result;
}

From source file:Main.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createMenu("Menu 1"));
    menuBar.add(createMenu("Menu 2"));
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(createMenu("Menu 3"));
    return menuBar;
}

From source file:HBoxWithGlue.java

public HBoxWithGlue() {
    super("Box & Glue Frame");
    setSize(350, 100);/*  w w  w.ja va  2  s. c om*/
    Box box = Box.createHorizontalBox();
    setContentPane(box);
    box.add(Box.createHorizontalGlue());
    for (int i = 0; i < 3; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }
    box.add(Box.createHorizontalGlue());
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:BoxLayoutGlueStrutCompare.java

public BoxLayoutGlueStrutCompare() {
    JPanel p = new JPanel(new GridLayout(3, 1));

    JPanel p1 = new JPanel();
    Box box1 = new Box(BoxLayout.X_AXIS);
    box1.add(Box.createHorizontalGlue());
    box1.add(new JButton("glue-strut"));
    box1.add(Box.createHorizontalStrut(15));
    box1.add(new JButton("strut-glue"));
    box1.add(Box.createHorizontalGlue());
    p1.add(box1);/* w ww.  ja  va  2s  .  c om*/
    p1.setBorder(BorderFactory.createRaisedBevelBorder());

    JPanel p2 = new JPanel();
    Box box2 = new Box(BoxLayout.X_AXIS);
    box2.add(Box.createHorizontalStrut(25));
    box2.add(new JButton("strut-glue"));
    box2.add(Box.createHorizontalGlue());
    box2.add(new JButton("glue-strut"));
    box2.add(Box.createHorizontalStrut(25));
    p2.add(box2);
    p2.setBorder(BorderFactory.createRaisedBevelBorder());

    JPanel p3 = new JPanel();
    Box box3 = new Box(BoxLayout.X_AXIS);
    box3.add(Box.createHorizontalStrut(25));
    box3.add(new JButton("strut-glue"));
    box3.add(Box.createHorizontalGlue());
    box3.add(new JButton("glue-glue"));
    box3.add(Box.createHorizontalGlue());
    p3.add(box3);
    p3.setBorder(BorderFactory.createRaisedBevelBorder());

    p.add(p1);
    p.add(p2);
    p.add(p3);
    getContentPane().add(p);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
}

From source file:Main.java

/**
 * Initialises the {@link JDialog} for the {@link JComponent}.
 * /*from  w w w  .j a v  a2s. com*/
 * @param dialog
 * @param component
 * @param parentComponent
 */
private static void initDialog(final JDialog dialog, final JComponent component,
        final Component parentComponent) {
    dialog.setResizable(true);
    dialog.setComponentOrientation(component.getComponentOrientation());
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(component, BorderLayout.CENTER);

    final int buttonWidth = 75;

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));

    buttonPanel.add(Box.createHorizontalGlue());

    @SuppressWarnings("serial")
    final Action closeAction = new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };

    final JButton button = new JButton(closeAction);
    fixWidth(button, buttonWidth);
    buttonPanel.add(button);

    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    WindowAdapter adapter = new WindowAdapter() {
        //         private boolean gotFocus = false;
        public void windowClosing(WindowEvent we) {
            fireAction(we.getSource(), closeAction, "close");
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
}

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 ww  .java  2  s.c o  m*/
    bv.add(Box.createVerticalGlue());
    getContentPane().add(bv);
}