Java examples for Swing:FlowLayout
FlowLayout tries to lay out all components in only one row.
import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; public class Main { public static void main(String[] argv) throws Exception { JFrame frame = new JFrame("flow layout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new FlowLayout()); for (int i = 1; i <= 30; i++) { frame.getContentPane().add(new JButton("Button " + i)); }// ww w .ja va2 s . c om frame.pack(); frame.setVisible(true); } }