Java JPanel Create vgrid(JPanel panel, List components, int space)

Here you can find the source of vgrid(JPanel panel, List components, int space)

Description

Do a single column grid layout of the components

License

Open Source License

Parameter

Parameter Description
panel The panel to add to
components The components to layout
space The spacing

Return

The panel

Declaration

public static JPanel vgrid(JPanel panel, List components, int space) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.ja v a2 s  . c om*/
 * $Id: GuiUtils.java,v 1.317 2007/08/10 14:26:33 jeffmc Exp $
 *
 * Copyright  1997-2016 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.awt.*;

import java.util.List;

import javax.swing.*;

public class Main {
    /**
     * Do a single column  grid layout of the components
     *
     * @param components The components to layout
     * @return The new JPanel
     */
    public static JPanel vgrid(List components) {
        return vgrid(new JPanel(), components, 0);
    }

    /**
     * Do a single column  grid layout of the components
     *
     * @param panel The panel to add to
     * @param components The components to layout
     * @param space The spacing
     * @return The panel
     */
    public static JPanel vgrid(JPanel panel, List components, int space) {
        if (panel == null) {
            panel = new JPanel();
        }
        panel.setLayout(new GridLayout(0, 1, space, space));
        for (int i = 0; i < components.size(); i++) {
            panel.add((Component) components.get(i));
        }
        return panel;
    }
}

Related

  1. initPanel(Color color)
  2. newJPanel(Component... c)
  3. newJPanel(int layoutAxis, Component... components)
  4. setJPanelOpaque(JPanel p, boolean opaque)
  5. vbox(JPanel panel, List components)