• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Mystery GridBagLayout

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
i have the follwong code and what i supposed after going thru the code that i will get a Frame with panel in one of the grids and inside that panel i will have two buttons. but the panel occupies the total area of Frame . pls Explain this behavior of GridLayout..
Thanks in Advance....
Here the Code Goes...
import java.awt.*;
public class LayoutFrame extends Frame{
public LayoutFrame()
{
setLayout(new GridLayout(1, 3));
Button b = new Button("What is b location?");
Button a = new Button("What is a location?");
Panel p1 = new Panel();
p1.setLayout(new GridLayout(2, 1));
p1.add(a);
p1.add(b);
add(p1);
}
public static void main(String args[]) {
LayoutFrame tf = new LayoutFrame();
tf.setSize(300,400);
tf.setVisible(true);
}
}
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have some points to say about GridLayout. I haven't read any of these in books. They are found by experimentation. I hope my conclusions are right. Correct me if I am wrong.
1. If number of components added to the container with GridLayout, are equal or greater than the number of rows specified in the GridLayout constructor, then number of rows are ignored. It just creates number of rows specified and goes on adding components from top to bottom.

This explains behaviour of the program you have posted.
2. If number of components is more than number of grids that can be formed using rows and columns specified in the constructor, then number of rows are created as per the arguments in the constructor and number of columns are created so as to accomodate the number of components.
Hope this helps.
Milind.
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic