import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestGridLayout extends JFrame { public TestGridLayout(String [] nomsBoutons, int ncol) { super("GridLayout"); Container c = getContentPane(); c.setLayout(new GridLayout(0, ncol)); for (int i = 0; i < nomsBoutons.length; i++) { JButton b = new JButton(nomsBoutons[i]); c.add(b); } addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public static void main(String [] args) { String [] nomsBoutons = {"Heureux", "qui", "comme", "Ulysse", "a", "fait", "un", "beau", "voyage", "ou", "comme", "cestui-la", "a", "conquis", "la", "toison", "..."}; JFrame tgl = new TestGridLayout(nomsBoutons, 4); tgl.pack(); tgl.setVisible(true); } }