I defined a GridBagLayout and put three component in it,I want to get this goal 
which I want to every component in the GridBagLayout occupy equal col size,like 
follows:

  
   col 
row 0                 1                  2 
 0  _________________________________________________________
 1 |  This is a test1 |                  |                   |
 2 |  test2           |                  |                   |
 3 |                  |                  |                   |
 4 |                  |                  |                   |
 5 |     one          |       two        |      thre         |
    ---------------------------------------------------------

So I design my code like follows:
JLabel label1=new JLabel("This is a test");
JLabel label2=new JLabel("test2");
JButton button1=new JButton("one");
JButton button2=new JButton("two");
JButton button3=new JButton("thre");
GridBagLayout gbLayout=new GridBagLayout();
GridBagConstraints gbConstraints=GridBagConstraints();
Container c=getContentPane();
c.setLayout(gbLayout);

//add label1
gbConstraints.weightx=0;
gbConstraints.weighty=0;
gbConstraints.gridx=0;
gbConstraints.gridy=0;
gbConstraints.gridwidth=1;
gbConstraints.gridheight=1;
gbConstraints.anchor=GridBagConstraints.WEST;
gbLayout.setConstraints(label1,gbConstraints);
c.add(label1);

//add label2
gbConstraints.gridy=1;
gbLayout.setConstraints(label2,gbConstraints);
c.add(label2);

//add button1
gbConstraints.gridx=0;
gbConstraints.gridy=5;
gbLayout.setConstraints(button1,gbConstraints);
c.add(button1);

//add button2
gbConstraints.gridx=1;
gbConstraints.gridy=5;
gbLayout.setConstraints(button2,gbConstraints);
c.add(button2);

//add button3
gbConstraints.gridx=2;
gbConstraints.gridy=5;
gbLayout.setConstraints(button1,gbConstraints);
c.add(button3);
show();

But when I run it,I found I got another result,each JButton occupy different col 
size,why?
  col 
row 0                 1        2 
 0  _____________________________________
 1 |  This is a test1 |        |         |
 2 |  test2           |        |         |
 3 |                  |        |         |
 4 |                  |        |         |
 5 |     one          |  two   |  thre   |
    --------------------------------------

I want to make JButton one,two and three looks occupy equal width in the screen. But 
JButtone looks bigger than JButton two and JButton three. How to make three JButtons 
look equal width size?

Thanks in advance!







      
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to