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
|
public MyPanel(){
super();
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
un = new JLabel("Button 1");
un.setOpaque(true);
un.setBackground(new Color(191,28,28));
c.weightx = 0.5;
c.weighty = 100;
//un.setPreferredSize(new Dimension(400, 500));
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
this.add(un, c);
deux = new JLabel("Button 2");
//deux.setPreferredSize(new Dimension(400, 500));
deux.setOpaque(true);
deux.setBackground(new Color(28,174,191));
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 1;
c.gridy = 0;
this.add(deux, c);
trois = new JLabel("Button 3");
trois.setOpaque(true);
//trois.setize(new Dimension(400, 500));
trois.setBackground(new Color(28,33,191));
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 2;
c.gridy = 0;
this.add(trois, c); |
Partager