• 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 question

 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?)
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
I think I'll just lie down here for a second. And ponder 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