Java JPanel Child addInput2Pane(String label, Component c, JPanel p, int row)

Here you can find the source of addInput2Pane(String label, Component c, JPanel p, int row)

Description

add the component with the label at left to the JPanel at row

License

Open Source License

Declaration

public static void addInput2Pane(String label, Component c, JPanel p, int row) throws AWTException 

Method Source Code

//package com.java2s;
/****************************************************
Statistics Online Computational Resource (SOCR)
http://www.StatisticsResource.org/*from www .j a  va 2s . c  o m*/
     
All SOCR programs, materials, tools and resources are developed by and freely disseminated to the entire community.
Users may revise, extend, redistribute, modify under the terms of the Lesser GNU General Public License
as published by the Open Source Initiative http://opensource.org/licenses/. All efforts should be made to develop and distribute
factually correct, useful, portable and extensible resource all available in all digital formats for free over the Internet.
     
SOCR resources are distributed in the hope that they will be useful, but without
any warranty; without any explicit, implicit or implied warranty for merchantability or
fitness for a particular purpose. See the GNU Lesser General Public License for
more details see http://opensource.org/licenses/lgpl-license.php.
     
http://www.SOCR.ucla.edu
http://wiki.stat.ucla.edu/socr
 It s Online, Therefore, It Exists! 
****************************************************/

import java.awt.AWTException;
import java.awt.Component;
import java.awt.Container;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main {
    /** add the component with the label at left to the JPanel at row */
    public static void addInput2Pane(String label, Component c, JPanel p, int row) throws AWTException {
        JLabel jlabel = new JLabel(label);
        int a = GridBagConstraints.EAST, f = GridBagConstraints.HORIZONTAL;
        addComponent(p, jlabel, 0, row, 1, 1, f, a, 0, 0);
        addComponent(p, c, 1, row, 1, 1, f, a, 1, 1);
    }

    /**
     * Adds a component into a container component of <code> GridBagLayout.
     *
     * @param container a <code>Container </code> where a component will be added
     * @param c a <code> Component </code> to be added into a container
     * @param x an interger specifying the x coordiante of the added component
     * @param y an integer specifying the y coordinate of the added component
     * @param w an integer specifying the width of the added component
     * @param h an integer specifying the height of the added component
     * @param anchor an interger specifying the anchor point of the added component
     * @param wx an double specifying the extra horizontal space distribution
     * @param wy an double specifying the extra vertical space distribution
     * @throws AWTException Abstract Window Toolkit exception
     */
    public static void addComponent(Container container, Component c, int x, int y, int w, int h, int fill,
            int anchor, int wx, int wy) throws AWTException {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 2, 2);
        gbc.gridx = x;
        gbc.gridy = y;
        gbc.gridwidth = w;
        gbc.gridheight = h;
        gbc.fill = fill;
        gbc.anchor = anchor;
        gbc.weightx = wx;
        gbc.weighty = wy;
        addComponent(container, c, gbc);
    }

    public static void addComponent(Container container, Component c, int x, int y, int w, int h)
            throws AWTException {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 2, 2);
        gbc.gridx = x;
        gbc.gridy = y;
        gbc.gridwidth = w;
        gbc.gridheight = h;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.WEST;
        addComponent(container, c, gbc);
    }

    public static void addComponent(Container container, Component c, GridBagConstraints gbc) throws AWTException {
        LayoutManager lm = container.getLayout();
        if (!(lm instanceof GridBagLayout)) {
            throw new AWTException("Invalid layout" + lm);
        } else {
            container.add(c, gbc);
        }
    }
}

Related

  1. addComponent(JPanel contentPane, GridBagConstraints gbc, JLabel label, JComponent component)
  2. addComponent(JPanel panel, Component c, int x, int y, int width, int height, int ipadx, int ipady, double weightx, double weighty, int fill, int anchor)
  3. addComponents(JPanel panel, JComponent... comps)
  4. addGBC(JPanel panel, Component component, int gridx, int gridy, int anchor, Insets insets)
  5. addSection(JPanel panel, String title)
  6. addSpacer(JPanel panel)
  7. addTo(JPanel panel, String label, String value)
  8. addToGridBag(Component comp, JPanel panel, int gridx, int gridy, int width, int height, int anchor)