• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

grid back gridx

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why does the gridbag layout ignore the gridwidth and gridheight of 2 in the
following code. When the comment of btn5 are removed then the right output is
shown. Only when there are surrounding buttons a component can be extended to
have twice gridheight,gridwidth???

import java.awt.*;
public class Testgridbag4 extends Frame{
public static void main(String argv[]){
Testgridbag4 tbj = new Testgridbag4();
tbj.setSize(300,400);
tbj.setVisible(true);
}
public Testgridbag4(){
Button btn;
GridBagLayout gridbag = new GridBagLayout();
setLayout(gridbag);
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
btn = new Button("hello ");
add(btn);
gridbag.setConstraints(btn, constraints);
//add another button
Button btn1 = new Button("howdy");
add(btn1);
constraints.gridx=1;
constraints.gridy=0;
gridbag.setConstraints(btn1,constraints);
//add another button
Button btn2 = new Button("zain");
add(btn2);
constraints.gridx=0;
constraints.gridy=1;
gridbag.setConstraints(btn2,constraints);
/*//add another button
Button btn5 = new Button("zain");
add(btn5);
constraints.gridx=0;
constraints.gridy=2;
gridbag.setConstraints(btn5,constraints);
*///add another button
Button btn3 = new Button("zain3");
add(btn3);
constraints.gridx=1;
constraints.gridy=1;
constraints.gridwidth= 2;//GridBagConstraints.REMAINDER;
constraints.gridheight = 2;
constraints.fill= GridBagConstraints.BOTH;
gridbag.setConstraints(btn3,constraints);
}
}
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that. I got distracted with all that slapstick comedy going on here(browser upgrade).
Its because...
<pre>
public class Testgridbag4 extends Frame
{
public static void main(String argv[])
{
Testgridbag4 tbj = new Testgridbag4();
tbj.setSize(300, 400);
tbj.setVisible(true);
}
public Testgridbag4()
{
Button btn;
GridBagLayout gridbag = new GridBagLayout();
setLayout(gridbag);
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
btn = new Button("hello ");
add(btn);
gridbag.setConstraints(btn, constraints);
//add another button
Button btn1 = new Button("howdy");
add(btn1);
constraints.gridx=1;
constraints.gridy=0;
gridbag.setConstraints(btn1,constraints);
//add another button
Button btn2 = new Button("zain");
add(btn2);
constraints.gridx=0;
constraints.gridy=1;
gridbag.setConstraints(btn2,constraints);
Button btn3 = new Button("zain3");
add(btn3);
constraints.gridx=1;
constraints.gridy=1;
constraints.gridwidth= 2;
constraints.gridheight = 2;
constraints.weightx = 1.0; // ***** You forgot this *********
constraints.weighty = 1.0; //******* and this **************
constraints.fill= GridBagConstraints.BOTH;
gridbag.setConstraints(btn3,constraints);
}
}
</pre>
Rgds
Sahir

[This message has been edited by Sahir Shah (edited December 10, 2000).]
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
huh???
Because...???
 
reply
    Bookmark Topic Watch Topic
  • New Topic