Here you can find the source of addToGridBag(final JPanel panel, final Component component, final int x, final int y)
public static void addToGridBag(final JPanel panel, final Component component, final int x, final int y)
//package com.java2s; // Licensed under the MIT license. See License.txt in the project root. import javax.swing.JPanel; import java.awt.Component; import java.awt.GridBagConstraints; public class Main { public static void addToGridBag(final JPanel panel, final Component component, final int x, final int y) { addToGridBag(panel, component, x, y, 1, 1, -1, -1); }//from w ww. j ava 2 s .co m public static void addToGridBag(final JPanel panel, final Component component, final int x, final int y, final int spanX, final int spanY) { addToGridBag(panel, component, x, y, spanX, spanY, -1, -1); } public static void addToGridBag(final JPanel panel, final Component component, final int x, final int y, final int spanX, final int spanY, final int topMargin, final int rightMargin) { GridBagConstraints c = new GridBagConstraints(); c.gridx = x; c.gridy = y; c.gridwidth = spanX; c.gridheight = spanY; if (rightMargin >= 0) { c.insets.right = rightMargin; } if (topMargin != 0) { c.insets.top = topMargin; } c.anchor = GridBagConstraints.WEST; panel.add(component, c); } }