Example usage for java.awt GridBagLayout setConstraints

List of usage examples for java.awt GridBagLayout setConstraints

Introduction

In this page you can find the example usage for java.awt GridBagLayout setConstraints.

Prototype

public void setConstraints(Component comp, GridBagConstraints constraints) 

Source Link

Document

Sets the constraints for the specified component in this layout.

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.  j  a v  a 2 s  .  c  o  m
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.weightx = 1;
    gbc.weighty = 2;
    gbl.setConstraints(component, gbc);

    frame.pack();
    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   w  ww . j a v  a 2 s  .  co m*/
    JButton component = new JButton("1");

    frame.add(new JButton("2"));
    frame.add(new JButton("3"));
    frame.add(new JButton("4"));
    frame.add(new JButton("5"));
    frame.add(component);
    frame.add(new JButton("6"));
    frame.add(new JButton("7"));
    frame.add(new JButton("8"));
    frame.add(new JButton("9"));
    frame.add(new JButton("0"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    int top = 20;
    int left = 20;
    int bottom = 2;
    int right = 40;
    gbc.insets = new Insets(top, left, bottom, right);

    gbl.setConstraints(component, gbc);

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

From source file:TryGridBagLayout.java

static void addButton(String label, GridBagConstraints constraints, GridBagLayout layout) {
    Border edge = BorderFactory.createRaisedBevelBorder();
    JButton button = new JButton(label);
    button.setBorder(edge);//  w  w w .  j  a  v a  2  s .  com
    layout.setConstraints(button, constraints);
    aWindow.getContentPane().add(button);
}

From source file:Main.java

/**
 * @param gx/*from  ww  w .  ja  v  a 2 s.c o  m*/
 * @param gy
 * @param gw
 * @param gh
 * @param wx
 * @param wy
 * @param what
 * @param where
 * @param gbc
 * @param gridbag
 */
public static void add(int gx, int gy, int gw, int gh, int wx, int wy, Component what, Container where,
        GridBagConstraints gbc, GridBagLayout gridbag) {
    gbc.gridx = gx;
    gbc.gridy = gy;
    gbc.gridwidth = gw;
    gbc.gridheight = gh;
    gbc.weightx = wx;
    gbc.weighty = wy;
    gridbag.setConstraints(what, gbc);
    where.add(what);
}

From source file:Main.java

public static void addGridBagComponent(Container container, GridBagLayout gridbag, GridBagConstraints c,
        Component com, int gridx, int gridy, int gridwidth, int gridheight) {
    c.gridx = gridx;//  w  ww.jav a2  s.c  o m
    c.gridy = gridy;
    c.gridwidth = gridwidth;
    c.gridheight = gridheight;
    gridbag.setConstraints(com, c);
    container.add(com);
}

From source file:Main.java

static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x,
        final int y, final int width, final int height, final double weightx, final double weighty, int fill) {
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = fill;//GridBagConstraints.BOTH;
    gbc.gridx = x;//from  w  ww . ja  va  2  s  .c  om
    gbc.gridy = y;
    gbc.gridwidth = width;
    gbc.gridheight = height;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbl.setConstraints(c, gbc);
    cont.add(c);
}

From source file:Main.java

public static void addComponentToGridBagLayout(Container cont, GridBagLayout gbl, int x, int y, int width,
        int height, double weightx, double weighty, Component component) {
    GridBagConstraints gbc = new GridBagConstraints();

    if (y == 0)/*  w  w  w.j  a  v  a  2s .c  o  m*/
        gbc.insets = new Insets(8, 6, 4, 6);
    else
        gbc.insets = new Insets(4, 6, 4, 6);

    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = x;
    gbc.gridy = y;
    gbc.gridwidth = width;
    gbc.gridheight = height;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbl.setConstraints(component, gbc);
    cont.add(component);
}

From source file:Main.java

public static void addComponent(final Container container, final GridBagLayout gbl, final Component c,
        final int x, final int y, final int width, final int height, final double weightx, final double weighty,
        final int anchor, final int fill, final Insets insets) {
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = fill;//  ww w  .j  a v  a 2s .  c o  m
    gbc.gridx = x;
    gbc.gridy = y;
    gbc.gridwidth = width;
    gbc.gridheight = height;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbc.anchor = anchor;
    gbc.insets = insets;
    gbl.setConstraints(c, gbc);
    container.add(c);
}

From source file:Main.java

public static void addComponent(Container container, GridBagLayout gbl, Component c, int x, int y, int width,
        int height, double weightx, double weighty, int anchor, int ipadx, int ipady, int fill) {
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = fill;// w  w w .ja  v a  2 s.com
    gbc.gridx = x;
    gbc.gridy = y;
    gbc.gridwidth = width;
    gbc.gridheight = height;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbc.anchor = anchor;
    gbc.ipadx = ipadx;
    gbc.ipady = ipady;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbl.setConstraints(c, gbc);
    container.add(c);
}

From source file:Main.java

protected void makebutton(String name, GridBagLayout gridbag, GridBagConstraints c) {
    Button button = new Button(name);
    gridbag.setConstraints(button, c);
    add(button);//  ww  w .  j a v a  2s  . c  o  m
}