Java tutorial
//package com.java2s; import javax.swing.*; import java.awt.*; public class Main { /** * Put a series of {@link JComponent}s in a {@link JPanel} which has a {@link FlowLayout}. * * @param position * Position of components, left, right, or center justified (for example, {@link * java.awt.FlowLayout#CENTER)} * @param opaque * True if the returned JPanel should be opaque * @param firstComponent * The first {@link JComponent} to add * @param remainingComponents * The rest of the {@link JComponent}s to add * @return A {@link JPanel} with a {@link FlowLayout} which contains all the passed {@link JComponent}s. */ public static JPanel putComponentsInFlowLayoutPanel(int position, boolean opaque, JComponent firstComponent, JComponent... remainingComponents) { JPanel flowLayoutPanel = new JPanel(new FlowLayout(position)); flowLayoutPanel.setOpaque(opaque); flowLayoutPanel.add(firstComponent); for (JComponent component : remainingComponents) { flowLayoutPanel.add(component); } return flowLayoutPanel; } }