Here you can find the source of createTable(Component... comps)
comp1 comp2 comp3 comp4
Parameter | Description |
---|---|
comps | (an even number of components) |
public static JPanel createTable(Component... comps)
//package com.java2s; /*//from w w w . ja v a 2 s. 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; import javax.swing.JPanel; public class Main { public static JPanel createTable(List<? extends Component> comps) { return createTable(comps.toArray(new Component[comps.size()])); } /** * Creates a form panel * <pre> * comp1 comp2 * comp3 comp4 * </pre> * * * @param comps (an even number of components) * @return */ public static JPanel createTable(Component... comps) { return createTable(2, comps); } public static JPanel createTable(int columns, List<? extends Component> comps) { return createTable(columns, 0, 0, comps.toArray(new Component[comps.size()])); } public static JPanel createTable(int columns, int ipadx, int ipady, List<? extends Component> comps) { return createTable(columns, ipadx, ipady, comps.toArray(new Component[comps.size()])); } public static JPanel createTable(int columns, Component... comps) { return createTable(columns, 0, 0, comps); } public static JPanel createTable(int columns, int ipadx, int ipady, Component... comps) { JPanel panel = new JPanel(new GridBagLayout()); panel.setOpaque(false); GridBagConstraints c = new GridBagConstraints(); c.ipadx = ipadx; c.ipady = ipady; int count = 0; for (Component comp : comps) { c.anchor = GridBagConstraints.WEST; c.weighty = 0; c.weightx = count % columns < columns - 1 ? 0 : 1; c.gridx = count % columns; c.gridy = count / columns; if (comp != null) panel.add(comp, c); count++; } c.gridy++; c.weighty = 1; panel.add(Box.createGlue(), c); return panel; } }