new GridBagConstraints(int gx, int gy, int gw, int gh, double wx, double wy, int a, int f, Insets i, int ipx, int ipy) : GridBagConstraints « java.awt « Java by API






new GridBagConstraints(int gx, int gy, int gw, int gh, double wx, double wy, int a, int f, Insets i, int ipx, int ipy)

 

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;

public class MainClass {

  public static void main(String[] a) {
    final JFrame frame = new JFrame("GridBagLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridBagLayout());
    JButton button;

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

  private static void addComponent(Container container, Component component, int gridx, int gridy,
      int gridwidth, int gridheight, int anchor, int fill) {
    Insets insets = new Insets(0,0,0,0);
    GridBagConstraints gbc = new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0,
        anchor, fill, insets, 0, 0);
    container.add(component, gbc);
  }
}

           
         
  








Related examples in the same category

1.GridBagConstraints.BOTH
2.GridBagConstraints.CENTER
3.GridBagConstraints.NONE
4.GridBagConstraints.RELATIVE
5.new GridBagConstraints()
6.GridBagConstraints.fill
7.GridBagConstraints.gridheight
8.GridBagConstraints.gridwidth
9.GridBagConstraints.gridx
10.GridBagConstraints.gridy
11.GridBagConstraints.ipadx
12.GridBagConstraints.ipady
13.GridBagConstraints.weightx
14.GridBagConstraints.weighty