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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package test;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class Test extends JFrame {
private JTextArea panel1 = new JTextArea(5, 20);
private JTextArea panel2 = new JTextArea(5, 20);
private JButton bouton1 = new JButton("Bouton 1");
private JButton bouton2 = new JButton("Bouton 2");
private JTextField texte1 = new JTextField("Texte 1");
private JTextField texte2 = new JTextField("Texte 2");
public void init() {
GridBagLayout l = new GridBagLayout();
getContentPane().setLayout(l);
GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 1, 1,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
10, 10, 10, 10), 0, 0);
l.setConstraints(panel1, c);
getContentPane().add(panel1);
c.gridx = 1;
l.setConstraints(panel2, c);
getContentPane().add(panel2);
c.gridx = 0;
c.gridy = 1;
c.anchor = GridBagConstraints.EAST;
c.fill = GridBagConstraints.NONE;
c.weightx = 0;
c.weighty = 0;
l.setConstraints(bouton1, c);
getContentPane().add(bouton1);
c.gridx = 1;
l.setConstraints(bouton2, c);
getContentPane().add(bouton2);
c.gridx = 0;
c.gridy = 2;
c.anchor = GridBagConstraints.WEST;
l.setConstraints(texte1, c);
getContentPane().add(texte1);
c.gridx = 1;
l.setConstraints(texte2, c);
getContentPane().add(texte2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Test fenetre = new Test();
fenetre.init();
fenetre.setVisible(true);
}
});
}
} |
Partager