Example usage for java.awt GridBagConstraints NONE

List of usage examples for java.awt GridBagConstraints NONE

Introduction

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

Prototype

int NONE

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

Click Source Link

Document

Do not resize the component.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);//from  ww  w .ja v  a2 s. c om
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    gbc.fill = GridBagConstraints.NONE;

    gbl.setConstraints(component, gbc);
    frame.add(component);

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    final JFrame frame = new JFrame("GridBagLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridBagLayout());
    JButton button;/* w w w.j  av  a  2  s  .c  o m*/

    button = new JButton("One");
    addComponent(frame, button, 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
    button = new JButton("Two");
    addComponent(frame, button, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE);

    button = new JButton("Three");
    addComponent(frame, button, 0, 1, 2, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE);

    button = new JButton("Four");
    addComponent(frame, button, 0, 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
    frame.setSize(500, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);//from   ww  w .  j a  v  a 2 s .  co  m
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    // Make the component on stretchable
    gbc.fill = GridBagConstraints.NONE;

    gbl.setConstraints(component, gbc);
    frame.add(component);

    frame.pack();
    frame.setVisible(true);
}

From source file:GridBagLayoutGridHeight.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    pane.add(new JLabel("First row, first column"), gbc);
    pane.add(new JLabel("First row, second column"), gbc);
    gbc.gridheight = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.VERTICAL;
    pane.add(new JLabel("First row, third column"), gbc);
    gbc.gridx = 0;//  ww  w. j  a  v  a 2s .c o  m
    gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.NONE;
    pane.add(new JButton("Second row"), gbc);
    pane.add(new JButton("Third row"), gbc);
    f.setSize(600, 300);
    f.setVisible(true);
}

From source file:GridBagLayoutColumnSpanHORIZONTAL.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;/*ww w.  j a  va  2s.c om*/
    gbc.gridy = GridBagConstraints.RELATIVE;
    pane.add(new JButton("First row, first column"), gbc);
    pane.add(new JButton("Second row"), gbc);
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    pane.add(new JButton("Third row, spans two columns"), gbc);
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = GridBagConstraints.RELATIVE;
    pane.add(new JButton("First row, second column"), gbc);
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel userLabel = new JLabel("User Name");
    JLabel passLabel = new JLabel("Password");
    JTextField userText = new JTextField(20);
    JPasswordField passText = new JPasswordField(20);
    JButton loginButton = new JButton("Login");

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridx = 0;/*w  w  w. j a  v  a  2  s  .  c om*/
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(userLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(userText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(passLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(passText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridwidth = 2;
    panel.add(loginButton, gbc);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(panel));
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:GridBagWithWeight.java

public static void main(String[] args) {
    JFrame f = new JFrame("Demonstrates the use of fill constraints");
    JPanel p = new JPanel(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 2, 2);
    c.weighty = 1.0;/*from ww  w  .  ja  va2 s.c om*/
    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridheight = 2;
    c.fill = GridBagConstraints.BOTH; // Use both horizontal & vertical
    p.add(new JButton("Java"), c);
    c.gridx = 1;
    c.gridheight = 1;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.HORIZONTAL; // Horizontal only
    p.add(new JButton("Source"), c);
    c.gridy = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE; // Remember to reset to none
    p.add(new JButton("and"), c);
    c.gridx = 2;
    c.fill = GridBagConstraints.VERTICAL; // Vertical only
    p.add(new JButton("Support."), c);

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

    f.getContentPane().add(p);
    f.setSize(600, 200);
    f.show();
}

From source file:TextAcceleratorExample.java

public static void main(String[] args) {
    try {//w w  w  . j a  v a2  s. c o m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JLabel l;
    JTextField t;
    JButton b;
    JFrame f = new JFrame("Text Accelerator Example");
    Container cp = f.getContentPane();
    cp.setLayout(new GridBagLayout());
    cp.setBackground(UIManager.getColor("control"));
    GridBagConstraints c = new GridBagConstraints();

    c.gridx = 0;
    c.gridy = GridBagConstraints.RELATIVE;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.insets = new Insets(2, 2, 2, 2);
    c.anchor = GridBagConstraints.EAST;

    cp.add(l = new JLabel("Name:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('n');
    cp.add(l = new JLabel("House/Street:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('h');
    cp.add(l = new JLabel("City:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('c');
    cp.add(l = new JLabel("State/County:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('s');
    cp.add(l = new JLabel("Zip/Post code:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('z');
    cp.add(l = new JLabel("Telephone:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('t');
    cp.add(b = new JButton("Clear"), c);
    b.setMnemonic('l');

    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;

    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('n');
    c.gridx = 1;
    c.gridy = GridBagConstraints.RELATIVE;
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('h');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('c');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('s');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('z');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('t');
    c.weightx = 0.0;
    c.fill = GridBagConstraints.NONE;
    cp.add(b = new JButton("OK"), c);
    b.setMnemonic('o');

    f.pack();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setVisible(true);
}

From source file:Main.java

public static GridBagConstraints compConstraint(int gridx, int gridy, int anchor) {
    return compConstraint(gridx, gridy, GridBagConstraints.NONE, anchor);
}

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));
}