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
| import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class exo3 extends JFrame{
JPanel leconteneur =new JPanel();
JButton lebtn=new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
public exo3(){
this.setTitle("Fenetre gridbaglayout");
this.setSize(500, 420);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
leconteneur.setBackground(Color.RED);
leconteneur.setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets=new Insets(0, 5, 5, 0);
leconteneur.add(button3,gbc);
gbc=new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=1;
//gbc.insets=new Insets(0, 0, 0, 0);
leconteneur.add(lebtn,gbc);
gbc=new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
// gbc.insets=new Insets(0, 0, 0, 0);
leconteneur.add(button2,gbc);
this.setContentPane(leconteneur);
this.setVisible(true);
}
public static void main(String[] args) {
new exo3();
}
} |
Partager