Java Swing Border createVerticalBox(Border border, Component... comps)

Here you can find the source of createVerticalBox(Border border, Component... comps)

Description

create Vertical Box

License

Open Source License

Declaration

public static JPanel createVerticalBox(Border border, Component... comps) 

Method Source Code

//package com.java2s;
/*//from w  w w  .j  ava2s .  c  o  m
 * Spirit, a study/biosample management tool for research.
 * Copyright (C) 2018 Idorsia Pharmaceuticals Ltd., Hegenheimermattweg 91,
 * CH-4123 Allschwil, Switzerland.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 * @author Joel Freyss
 */

import java.awt.Component;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import java.util.List;

import javax.swing.Box.Filler;

import javax.swing.JPanel;

import javax.swing.border.Border;

public class Main {
    public static JPanel createVerticalBox(Border border, Component... comps) {
        JPanel res = createVerticalBox(comps);
        res.setBorder(border);
        return res;
    }

    public static JPanel createVerticalBox(Border border, List<? extends Component> comps) {
        JPanel res = createVerticalBox(comps);
        res.setBorder(border);
        return res;
    }

    public static JPanel createVerticalBox(List<? extends Component> comps) {
        return createVerticalBox(comps.toArray(new Component[0]));
    }

    public static JPanel createVerticalBox(Component... comps) {
        return createVerticalBox((int[]) null, comps);
    }

    public static JPanel createVerticalBox(int[] ratios, Component... comps) {
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        c.gridx = 0;
        c.gridy = GridBagConstraints.RELATIVE;
        c.anchor = GridBagConstraints.WEST;
        c.fill = GridBagConstraints.BOTH;
        for (int i = 0; i < comps.length; i++) {
            Component comp = comps[i];
            if (comp == null) {
                continue;
            } else if (comp instanceof Filler && ((Filler) comp).getMinimumSize().height == 0) {
                c.weightx = c.weighty = 1;
            } else {
                c.weightx = 1;
                c.weighty = ratios == null || i >= comps.length ? 0.01 : ratios[i];
            }
            panel.add(comp, c);
        }
        panel.setOpaque(false);

        return panel;
    }
}

Related

  1. createFormSectionBorder(Color color, String title)
  2. createJScrollPane(Component component, Rectangle bounds, Color backgroundColor, boolean noBorder, boolean visible)
  3. createRightBorder(int size, Color color)
  4. createRoundedEmptyBorder(final int top, final int left, final int bottom, final int right, final int arc, final Color color)
  5. createTitledBorder(Color color, String name)
  6. drawBorderTrans(Graphics2D g, JComponent focusOwner, JComponent area)
  7. drawBorderWhite(Graphics2D g, JComponent focusOwner, JComponent area)
  8. drawDisabledBorder(Graphics g, int x, int y, int w, int h)
  9. drawDisabledBorder(Graphics g, int x, int y, int w, int h)