Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

GridLayout  RSS feed

 
Christian Long
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having problems on layouts.
I am trying to use GridLayout(5,4)

p.add(button1)
p.add(b2)
p.add(b3)
p.add(b4)

Can I specify where the button 2 will be placed? I would like to place button3 in colum 2, row2.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The elements of GridLayout are layed left-to-right (or right-to-left, like its javadocs mention) and top-to-bottom. So to put something in column 2 of row 2, you need to fill up row 1 first, and then column 1 of row 2. If you don't have real GUI elements for those places, you can use JLabel with no text to keep those spots empty.

An alternative would be to use the (more complicated) GridBagLayout class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!