Java examples for Swing:GridLayout
Demonstrates how to use a GridLayout.
import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("GridLayout Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(3, 0)); for (int i = 1; i <= 13; i++) { buttonPanel.add(new JButton("Button " + i)); }/*from w ww . j a va 2 s . co m*/ contentPane.add(buttonPanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } }