1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public static void main(String[] args) {
JFrame frame = new JFrame("Démo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=GridBagConstraints.RELATIVE;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.weightx=1;
for(int i=0; i<3; i++) {
panel.add(new JButton("Button "+(i+1)),gbc);
}
// filler
gbc.fill=GridBagConstraints.BOTH;
gbc.weighty=1;
panel.add(new JPanel(),gbc); // ou bien panel.add(Box.createGlue(),gbc);
frame.add(panel);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} |