Example usage for java.awt GridBagConstraints WEST

List of usage examples for java.awt GridBagConstraints WEST

Introduction

In this page you can find the example usage for java.awt GridBagConstraints WEST.

Prototype

int WEST

To view the source code for java.awt GridBagConstraints WEST.

Click Source Link

Document

Put the component on the left side of its display area, centered vertically.

Usage

From source file:Main.java

public static GridBagConstraints defaultConstraints() {
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = 0;//from w  ww .j a v  a  2s.  c  om
    constraints.gridy = 0;
    constraints.ipadx = 3;
    constraints.ipady = 2;
    constraints.weightx = 1;
    //        constraints.weighty = 1;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.fill = GridBagConstraints.BOTH;
    return constraints;
}

From source file:Main.java

public static GridBagConstraints createConstraints(int gridx, int gridy, int gridwidth, int gridheight) {
    return createConstraints(gridx, gridy, gridwidth, gridheight, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(5, 0, 0, 0));
}

From source file:Main.java

public static GridBagConstraints createConstraints(int gridx, int gridy, int gridwidth, int gridheight,
        Insets insets) {/*w  w  w . j  av  a2  s . co  m*/
    return createConstraints(gridx, gridy, gridwidth, gridheight, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insets);
}

From source file:Main.java

public static JPanel createKV(final Component key, final Component value, final int keyWidth,
        final boolean fill) {
    initComponentHeight(key, value);// w ww.ja  va  2 s .co  m
    if (keyWidth > 0) {
        key.setPreferredSize(new Dimension(keyWidth, key.getPreferredSize().height));
    }
    final JPanel jp = new JPanel(new GridBagLayout());
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(0, 0, 0, 4);
    jp.add(key, gbc);
    gbc.gridx = 1;
    gbc.insets = new Insets(0, 0, 0, 0);
    gbc.weightx = 1.0;
    if (fill) {
        gbc.fill = GridBagConstraints.HORIZONTAL;
    }
    jp.add(value, gbc);
    return jp;
}

From source file:Main.java

public Main() {
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    getContentPane().setLayout(layout);//from   ww  w  .  j av  a2  s.  c o m
    constraints.anchor = GridBagConstraints.WEST;
    JLabel l1 = new JLabel("First Name:");
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5, 5, 5, 5);
    layout.setConstraints(l1, constraints);
    getContentPane().add(l1);

    JTextField t1 = new JTextField();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(5, 5, 5, 5);
    layout.setConstraints(t1, constraints);
    getContentPane().add(t1);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(700, 500);
}

From source file:Main.java

Main() {

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(500, 500);//from   w  ww .j a  v  a  2  s  .co m

    JPanel panel1 = new JPanel(new GridBagLayout());
    JButton b1 = new JButton("button 1"), b2 = new JButton("button 2");

    panel1.add(b1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    panel1.add(b2, new GridBagConstraints(1, 0, 1, 1, 2.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    add(panel1);
    setVisible(true);
}

From source file:GridBagConstraintsSimplePanel.java

public GridBagConstraintsSimplePanel() {
    super();//from  w w  w  .  j a  va2s  .c om
    GridBagConstraints constraints = new GridBagConstraints();
    GridBagLayout layout = new GridBagLayout();
    setLayout(layout);

    constraints.anchor = GridBagConstraints.WEST;

    constraints.gridy = 0;
    JLabel label = new JLabel("First name:");
    add(label, constraints);

    JTextField tf = new JTextField(8);
    add(tf, constraints);
    label = new JLabel("Last name:");
    add(label, constraints);

    tf = new JTextField(8);
    add(tf, constraints);

    constraints.gridy = 1;
    label = new JLabel("Address:");
    add(label, constraints);

    tf = new JTextField(10);
    add(tf, constraints);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    JPanel upper = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    upper.setLayout(gridbag);/*from  ww  w .  j  av a 2s  .  c  o m*/
    GridBagConstraints gbc = new GridBagConstraints();

    JButton toolbar1 = new JButton("toolbar1");
    JButton toolbar2 = new JButton("toolbar2");
    JButton toolbar3 = new JButton("toolbar3");

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    upper.add(toolbar1, gbc);

    gbc.gridx = 1;
    gbc.anchor = GridBagConstraints.CENTER;
    upper.add(toolbar2, gbc);

    gbc.gridx = 2;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    upper.add(toolbar3, gbc);

    add(upper, BorderLayout.NORTH);

    JPanel something = new JPanel();
    something.setBackground(Color.WHITE);
    something.setPreferredSize(new Dimension(600, 600));
    something.repaint();
    add(something, BorderLayout.CENTER);

    pack();
    setVisible(true);
}

From source file:Main.java

public LoginPanel() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.anchor = GridBagConstraints.CENTER;
    gbc.weightx = 1;/*from   w  w w  .j  a  va2 s .  c  o m*/
    gbc.gridx = 2;
    gbc.anchor = GridBagConstraints.EAST;
    JLabel label = new JLabel("Username: ");
    add(label, gbc);

    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 3;
    gbc.gridwidth = 2;
    add(userfield, gbc);

    gbc.gridy = 1;
    add(passfield, gbc);

    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridx = 2;
    label = new JLabel("Password: ");
    add(label, gbc);

    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridy = 2;
    gbc.gridx = 1;
    gbc.gridwidth = 5;
    add(new JSeparator(JSeparator.HORIZONTAL), gbc);
}

From source file:PizzaGridBagLayout.java

public PizzaGridBagLayout() {
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridBagLayout());
    addItem(panel1, new JLabel("Name:"), 0, 0, 1, 1, GridBagConstraints.EAST);
    addItem(panel1, new JLabel("Phone:"), 0, 1, 1, 1, GridBagConstraints.EAST);
    addItem(panel1, new JLabel("Address:"), 0, 2, 1, 1, GridBagConstraints.EAST);

    addItem(panel1, name, 1, 0, 2, 1, GridBagConstraints.WEST);
    addItem(panel1, phone, 1, 1, 1, 1, GridBagConstraints.WEST);
    addItem(panel1, address, 1, 2, 2, 1, GridBagConstraints.WEST);

    Box sizeBox = Box.createVerticalBox();
    ButtonGroup sizeGroup = new ButtonGroup();
    sizeGroup.add(small);//from   w w  w  .jav a  2 s . c  om
    sizeGroup.add(medium);
    sizeGroup.add(large);
    sizeBox.add(small);
    sizeBox.add(medium);
    sizeBox.add(large);
    sizeBox.setBorder(BorderFactory.createTitledBorder("Size"));
    addItem(panel1, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH);

    Box styleBox = Box.createVerticalBox();

    ButtonGroup styleGroup = new ButtonGroup();
    styleGroup.add(thin);
    styleGroup.add(thick);
    styleBox.add(thin);
    styleBox.add(thick);
    styleBox.setBorder(BorderFactory.

            createTitledBorder("Style"));
    addItem(panel1, styleBox, 1, 3, 1, 1, GridBagConstraints.NORTH);

    Box topBox = Box.createVerticalBox();
    ButtonGroup topGroup = new ButtonGroup();
    topGroup.add(pepperoni);
    topGroup.add(mushrooms);
    topGroup.add(anchovies);
    topBox.add(pepperoni);
    topBox.add(mushrooms);
    topBox.add(anchovies);
    topBox.setBorder(BorderFactory.createTitledBorder("Toppings"));
    addItem(panel1, topBox, 2, 3, 1, 1, GridBagConstraints.NORTH);

    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(okButton);
    buttonBox.add(Box.createHorizontalStrut(20));
    buttonBox.add(closeButton);
    addItem(panel1, buttonBox, 2, 4, 1, 1, GridBagConstraints.NORTH);

    this.add(panel1);
    this.pack();
    this.setVisible(true);
}