• 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

Which Layout

 
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to create the following Layout:

I have an outer panel.

I want 2 panels inside the outer panel. One aligned to the left; the other to the right with space between them

Which layout manager should I use.

Thanks.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want two panels of the same size then a FlowLayout would work just fine. You can control the space between them, there are parameters called "gap".
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FlowLayout would display each panel at its preferredSize. GridLayout would make them the same size, but resize both when the frame is resized, keeping a constant gap.

For the panels to display at their (possibly different) preferredSize(s) with the gap between them varying when resizing the frame, I would use a horizontal Box with horizontal glue between the panels. A minimum gap could be enforced with a horizontal strut.

GridBagLayout with appropriate anchor / fill constraints would also do the trick, but resizing smaller might result in one or both panels shrinking to the minimumSize.
 
J Noble
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I'm almost there,

Im using a box Layout with horizontal glue as suggested by Darryl.

Looks OK apart from the 2 inner panels are still growing in size when the frame is resized (along with the gap in the middle). I just want the gap in the middle to grow / shrink

I have tried to set the preferredSize to the inner panels but it does not seem to make any difference.

Can anyone advise ?

Here is an inner panel class...



The panel has 5 buttons inside it. I want the width of the panel to be slightly longed that the combined width of the 5 buttons. I need to add 300 to do this. Not sure why ???

Thanks,

J
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've found this override useful for a JPanel contained in a vertical BoxLayout:Since you're using a horizontal layout, you could try it with the width/height logic interchanged.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and keep away from setPreferredSize(...). That one bites
 
J Noble
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect!

Just what I needed. Thanks a lot.

J
reply
    Bookmark Topic Watch Topic
  • New Topic