setLayout with GridLayout there are 4 components. only when i do GridLayout(1,x) or (4,x) the orders are obeyed ie in first case it gives 1 row and in the second case it gives 4 rows, and (2,x) gives two rows layout. doing GridLayout(3,x) gives 2 rows layout. it just does not give 3 rows. why ? (also is GridBagLayout in the exam syllabus ? what are we supposed to know on this for the exam ?)
GridLayout has some surprising behavior when you don't use every row you specify. The condition that arises when you specify more rows than you will use is "handled" but probably not a result you hope for; that's where the fun starts. Here's an example that allocates a 3x3 layout but only adds four buttons. Run it and see what happens. Then, comment out add(b4), and run it again. See if you can infer a rule for what's going on.
Funky, huh? ------------------ Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Make visible what, without you, might perhaps never have been seen. - Robert Bresson
Hello Michael. I have been playing with your code for a while and these are my conclusions. Please confirm o deny. If we are adding fewer elements that those specified by the "grid" formed by the arguments to the constructor of the Gridlayout there are two cases: a)We are also adding fewer (or the same) elements than those especified as the argument for the rows: only one column is formed. b)We are adding more elements than the argument for the rows: the grid especified by the arguments is formed with blank spaces where no element habits. This blank space is also kept whe resizing the GridLaout window. An attempt for making the most columns is made, but never two adjacents columns will have a difference of cells greater than one.
SCJP2. Please Indent your code using UBB Code
The glass is neither half full or half empty. It is too big. But this tiny ad is just right: