Java tutorial
//package com.java2s; import java.awt.Component; import javax.swing.BoxLayout; import javax.swing.JPanel; public class Main { public static final Component groupHorizontal(final Component... components) { return group(components, BoxLayout.LINE_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; } }