File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes GridLayout troubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "GridLayout troubles" Watch "GridLayout troubles" New topic

GridLayout troubles

Aaron Parker

Joined: Jan 31, 2004
Posts: 27
Can anyone explain to me why when I run this code, I get 4 cols and 2 rows instead of 2 cols and 2 rows?

(Code tags added by Michael Morris)
[ April 23, 2004: Message edited by: Michael Morris ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
In this line

you tell the GridLayout layout manager that you want two rows and two columns. It is expecting to be handed 2 x 2 = 4 components to layout in this 2 x 2 grid. When you hand it 8 components it tries to put them in 2 rows...
Check the last paragraph in the GridLayout api for the explanation.

From this explanation, a common practice that is used in GridLayout is to specify either rows or cols and let the layout manager use the (unspecified) number of rows or cols it needs. If I want only two columns I can do:
I agree. Here's the link:
subject: GridLayout troubles
jQuery in Action, 3rd edition