Java tutorial
//package com.java2s; import java.awt.Component; import javax.swing.BoxLayout; import javax.swing.JPanel; public class Main { public static final Component groupVertical(final Component... components) { return group(components, BoxLayout.PAGE_AXIS); } private static final Component group(final Component[] components, final int axis) { final JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, axis)); for (final Component component : components) { panel.add(component); } return panel; } }