Java JPanel Child addToGridBag(final JPanel panel, final Component component, final int x, final int y)

Here you can find the source of addToGridBag(final JPanel panel, final Component component, final int x, final int y)

Description

add To Grid Bag

License

Open Source License

Declaration

public static void addToGridBag(final JPanel panel, final Component component, final int x, final int y) 

Method Source Code

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

Related

  1. addInput2Pane(String label, Component c, JPanel p, int row)
  2. addSection(JPanel panel, String title)
  3. addSpacer(JPanel panel)
  4. addTo(JPanel panel, String label, String value)
  5. addToGridBag(Component comp, JPanel panel, int gridx, int gridy, int width, int height, int anchor)
  6. addTwoCheckBoxes(JPanel panel, JCheckBox first, boolean firstChecked, JCheckBox second, boolean secondChecked)
  7. addUIComponent(JPanel jp, JComponent jc, int loc, int type, int[] decart, Insets insets)
  8. addWidth(JPanel panel, int width)
  9. addWithPadding(JPanel parentPanel, JPanel panelToBeAdded)