Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

GridLayout with less/more components.

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all...
Can someone explain me how does gridlayout work when there r less or
more components then the rows , colums specified in Gridlayout
For e.x if the gridlayout specify (2,3) & if 3 components r added then what is
the reason that the layout will put the 3rd component in 2nd row & 2 components in first row.
What i want to know is how does gridlayout take care of any additional
or even less componets then what is defined during the construction of
gridlayout.
Thanks
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Shah,
This is what I could find out.
The GridLayout class has three constructors.
1. GridLayout()
2. GridLayout(int Rows, int Columns)
3. GridLayout(int Rows, int Columns, int Hrgap, int Vrgap)
Constructor 1 is equivalent to 1 row and 0 columns.
In constructors 2 and 3, either rows or columns can be zero but not both.
According to Khalid Mughal components are added left to right, top to bottom (row-major) in the container. The geometry of the grid is determined by the non-zero parameter (row or column) and the number of components added.
So
1. if the number of rows is non-zero then the number of columns is ignored and the JVM figures out the number of columns based on the number of components being added to the container
Example. if rows = 4 and 3 components are being added then you will see a gid layout with one column with 3 components and a blank row at the bottom
Example. if rows = 4 and 9 components are being added number 1 thru 9 then you will a grid with 4 rows and three columns and the components will be filled row first
1 2 3
4 5 6
7 8 9
blank row
2. if number of rows is zero and number of columns is non-zero then the number of columns stay fixed and number of rows will depend upon the number of components being added
Example. if columns = 2 and 3 components are added
then two rows will be needed and the components are added row-major so you will see
1 2
3 blank
Example if columns = 4 and 2 components are added then you will see
1 2 blank blank
3. If both rows and columns are specified then the number of rows stays fixed and number of columns is figured out based on number of components added.
I hope I got this one right
Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic