Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; public class Main { public 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) { addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, GridBagConstraints.NORTH, GridBagConstraints.BOTH); } public 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, final int anchor, final int fill) { addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, anchor, fill, new Insets(0, 0, 0, 0)); } 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; 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); } }