• 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

Gridlayout

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a qstn regarding gridlayout. Let's see an ex.
If you have a gridlayout like Gridlayout(3,1) i.e 3 rows and 1 col and if you try to put 4 buttons. then it should first fill the three rows and then put the fourth button in the first row second col right. But it is distributing the buttons in two rows two col's why??
I thought it will show up like
but1 but2
but3
but4

But it's showing like
but1 but2
but3 but4
Please explain.
Will be waiting for your response.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thanuja,
The order of insertion is left to right, top to bottom.
Ajith
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thanjua,
I guess we don't have any control over GridLayout. According to the frame size it will be arranged.
Am I correct. Pls. correct me.
Thanks
Suryakumar
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thanuja,
In GridLayout:
1. Components appear in the order in which they are added, from
left to right, row by row.
2. If number of components > fixed rows and columns, then
number of culumns will be increased.
Considering the above points, you get the result as
but1 but2
but3 but4
Few more interesting points.
3. If you specify number of rows as zero, the layout manager
will provide as many rows in the grid as are necessary to
accomodate the number of components you add to the container.
4. Similarly, if you specify number of columns as zero,
arbitrary number of culmns will be provided.
5. Remember, you CANNOT specify both rows and columns as zero, which is quite obviuos.
I hope this helps you.
Suma

[This message has been edited by Suma Narayan (edited May 17, 2000).]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suryakumar,
yes. GridLayout is the meanest one from the component's preferred size point of view. In the sense it bothers neither preferred width/preferred height of the container's components. At the same time we can say it is a PERFECT MODERATOR by equally dividing the whole available container area and treating all the components SAME.
Also note that according to the frame size has to be sightly changed. If the Frame's layout is set to GridLayout type then the Frame's size is equally divided. If it is set to a Panel then the Panel's whole area is equally divided. So we should say GridLayout arranges all the components (gives each comp same size) accoding to the container's size the GridLayout is set as LayoutManager.
Frame is also a container.
regds
maha anna

[This message has been edited by maha anna (edited May 17, 2000).]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surya,
You are right, GridLayout will not honor the preferred size of your component. But the question here is not about the size, but about the order of placement of components. It is row major placement ie., it fills up the row before moving on to the next one.
Hope this clarifies.
Ajith
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suma,
Just one addition to your scenarios. You can create a GridLayout with no args. In such a case, it keeps the row fixed to one, and keeps on adding new columns to it every time you add a component.
I have seen such a question in one of the mock exam, I don't remember which one, where they constructed a GridLayout with no arguments and added a few components. One might get misled thinking that would cause a compiler error!!

Ajith
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ajith and Maha. Now I got it.
Surya
 
Suma Narayan
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajith,

First I thought I will add this scenario too but then decided not to as the question was about GridLayout(row, col).
Now, since you have mentioned this, there is one more constructor which is GridLayout(int rows, int cols, int hgap, int vgap)(where hgap and vgap are horizontal and vertical gaps between components). But I think hgap and vgap are not part of Certification (I am not sure). If it is not, then please don't worry about this constructor.
Suma
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more point to add to Suma's first post- if you specify both the number of rows and columns as non-zero, then the number of columns you specify is ignored, and instead determined only from the number of components actually added to the layout manager. As Suma said, this is also what happens when you specify that the number of columns is zero. So, the only way you can really specify the number of columns is to make the number of rows zero, and the number of columns non-zero. Then it uses the number of columns you specify, and adjusts the number of rows to fit the number of components.
Frankly, it's a rather poorly designed class IMO. The constructors are misleading - at least one of the parameters (rows or columns) is meaningless, however you call it. And the setColumns() method has no effect unless rows are set to zero. This is mentioned if you read the documentation, but it seems rather counterintuitive.
 
What's wrong? Where are you going? Stop! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic