Example usage for javax.swing Box createHorizontalStrut

List of usage examples for javax.swing Box createHorizontalStrut

Introduction

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

Prototype

public static Component createHorizontalStrut(int width) 

Source Link

Document

Creates an invisible, fixed-width component.

Usage

From source file:LabelForComboBox.java

public LabelForComboBox() {
    JLabel lbl = new JLabel("Color:");
    lbl.setDisplayedMnemonic('c');
    add(lbl);//from   w w  w  .  j a  v  a 2 s  .c o m
    add(Box.createHorizontalStrut(20));
    JComboBox cbColor = new JComboBox();
    cbColor.addItem("red");
    cbColor.addItem("blue");
    lbl.setLabelFor(cbColor);
    add(cbColor);
}

From source file:Main.java

public Main() {
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(new JButton("Foo"));
    buttonPanel.add(Box.createHorizontalStrut(10));
    buttonPanel.add(new JButton("Bar"));

    String[] columnNames = { "Mon", "Tues", "Wed" };
    DefaultTableModel model = new DefaultTableModel(columnNames, 25);
    JTable table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.getViewport().setPreferredSize(table.getPreferredSize());

    JLabel southLabel = new JLabel("OK!");
    southLabel.setForeground(Color.white);
    JPanel southPanel = new JPanel();
    southPanel.add(southLabel);/*from   w w w.ja va2 s  . c  o  m*/

    setLayout(new BorderLayout(5, 5));
    add(buttonPanel, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(southPanel, BorderLayout.SOUTH);
}

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);/*  ww  w.  j a v a  2s  . co  m*/
    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:Box2.java

public void init() {
    Box bv = Box.createVerticalBox();
    for (int i = 0; i < 5; i++) {
        bv.add(new JButton("bv " + i));
        bv.add(Box.createVerticalStrut(i * 10));
    }//  w w  w  .j a va2 s  . c  o  m
    Box bh = Box.createHorizontalBox();
    for (int i = 0; i < 5; i++) {
        bh.add(new JButton("bh " + i));
        bh.add(Box.createHorizontalStrut(i * 10));
    }
    Container cp = getContentPane();
    cp.add(BorderLayout.EAST, bv);
    cp.add(BorderLayout.SOUTH, bh);
}

From source file:HBoxWithStrut.java

public HBoxWithStrut() {
    super("Box & Strut Frame");
    setSize(370, 80);/*from   w  w w .  ja  va 2 s .c o m*/
    Box box = Box.createHorizontalBox();
    setContentPane(box);
    for (int i = 0; i < 3; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }

    // Add a spacer between the first three buttons and the last three
    box.add(Box.createHorizontalStrut(10));
    for (int i = 3; i < 6; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:Main.java

private Component createStrut() {
    JComponent component = (JComponent) Box.createHorizontalStrut(5);
    component.setMinimumSize(new Dimension(0, 0));
    component.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    return component;
}

From source file:CommonLayouts.java

public CommonLayouts() {
    super("Common Layout Managers");
    setSize(500, 380);//from w  w w . j a v a2  s .c  o  m

    JPanel desktop = new JPanel();
    getContentPane().add(desktop);

    JPanel fr1 = new JPanel();
    fr1.setBorder(new TitledBorder("FlowLayout"));
    fr1.setLayout(new FlowLayout());
    fr1.add(new JButton("1"));
    fr1.add(new JButton("2"));
    fr1.add(new JButton("3"));
    fr1.add(new JButton("4"));
    desktop.add(fr1, 0);

    JPanel fr2 = new JPanel();
    fr2.setBorder(new TitledBorder("GridLayout"));
    fr2.setLayout(new GridLayout(2, 2));
    fr2.add(new JButton("1"));
    fr2.add(new JButton("2"));
    fr2.add(new JButton("3"));
    fr2.add(new JButton("4"));
    desktop.add(fr2, 0);

    JPanel fr3 = new JPanel();
    fr3.setBorder(new TitledBorder("BorderLayout"));
    fr3.add(new JButton("1"), BorderLayout.NORTH);
    fr3.add(new JButton("2"), BorderLayout.EAST);
    fr3.add(new JButton("3"), BorderLayout.SOUTH);
    fr3.add(new JButton("4"), BorderLayout.WEST);
    desktop.add(fr3, 0);

    JPanel fr4 = new JPanel();
    fr4.setBorder(new TitledBorder("BoxLayout - X"));
    fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS));
    fr4.add(new JButton("1"));
    fr4.add(Box.createHorizontalStrut(12));
    fr4.add(new JButton("2"));
    fr4.add(Box.createGlue());
    fr4.add(new JButton("3"));
    fr4.add(Box.createHorizontalGlue());
    fr4.add(new JButton("4"));
    desktop.add(fr4, 0);

    JPanel fr5 = new JPanel();
    fr5.setBorder(new TitledBorder("BoxLayout - Y"));
    fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS));
    fr5.add(new JButton("1"));
    fr5.add(Box.createVerticalStrut(10));
    fr5.add(new JButton("2"));
    fr5.add(Box.createGlue());
    fr5.add(new JButton("3"));
    fr5.add(Box.createVerticalGlue());
    fr5.add(new JButton("4"));
    desktop.add(fr5, 0);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:Demo.LineGraph.java

public LineGraph(int sampleNb) {
    this.sampleNb = sampleNb;

    InitDataSet();/* ww w  .ja  v  a2s .  c om*/
    InitChart();

    // layout
    setLayout(new BorderLayout());

    add(Box.createHorizontalStrut(30), BorderLayout.WEST);
    add(Box.createHorizontalStrut(30), BorderLayout.EAST);
    add(Box.createVerticalStrut(30), BorderLayout.NORTH);
    add(chartPane, BorderLayout.CENTER);
}

From source file:be.fedict.eid.tsl.Pkcs11CallbackHandler.java

private char[] getPin() {
    Box mainPanel = Box.createVerticalBox();

    Box passwordPanel = Box.createHorizontalBox();
    JLabel promptLabel = new JLabel("eID PIN:");
    passwordPanel.add(promptLabel);//  w  ww  . j a  va 2  s  . c om
    passwordPanel.add(Box.createHorizontalStrut(5));
    JPasswordField passwordField = new JPasswordField(8);
    passwordPanel.add(passwordField);
    mainPanel.add(passwordPanel);

    Component parentComponent = null;
    int result = JOptionPane.showOptionDialog(parentComponent, mainPanel, "eID PIN?",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (result == JOptionPane.OK_OPTION) {
        char[] pin = passwordField.getPassword();
        return pin;
    }
    throw new RuntimeException("operation canceled.");
}

From source file:BoxLayoutTest.java

public Box createBox(boolean horizontal, boolean strutsAndGlue) {
    Box b;//from ww w.j a  va 2 s  .  c o  m
    if (horizontal)
        b = Box.createHorizontalBox();
    else
        b = Box.createVerticalBox();

    b.add(new JLabel("Name: "));
    b.add(new JTextField());

    if (strutsAndGlue)
        if (horizontal)
            b.add(Box.createHorizontalStrut(5));
        else
            b.add(Box.createVerticalStrut(5));

    b.add(new JLabel("Password: "));
    b.add(new JTextField());

    if (strutsAndGlue)
        b.add(Box.createGlue());

    b.add(new JButton("Ok"));

    return b;
}