Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting preferred Size vs occupying the available space

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What my intention is to occupy the rest of the available space
in my subpanels. But when I don't, the JPanels get weird size.
I am using the MigLayout, I try to hog 100% width inside every
JPanel it belongs to. But the outer JPanel has to be set
with a preferred size.

Like this case

the p JPanel and sp JScrollPane have to be preset with a size
In the client machines, we can't predict what the sizes would be in advance
How do I set the size to the maximum width and height of
the space available conveniently without knowing
what the client machine's resolution is.
Thanks
Jack
 
Bernhard Goetz
Ranch Hand
Posts: 57
1
Java Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I don't have a solution for MigLayout at hand. But I'd like to point you to GroupLayout. It allows to create anchors on borders, which may be the thing you need. But it's rather hard to write by hand. I recommend using a gui editor, like the excellent (and free!) Google WindowBuilder for Swing. Which I believe is also a good starting software to get in touch with Swing gui development in general.

Best regards,
Bernhard Goetz
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Control the layout, never the size. This way you never need to worry about the JFrame being resized or screen size or resolution.

e.g.

You can actually skip the BorderLayout.CENTER as it is the default.
The key is to choose a proper layout manager or have a structure with nested layouts as per your requirement

Bernhard Goetz wrote: But I'd like to point you to GroupLayout. It allows to create anchors on borders, which may be the thing you need. But it's rather hard to write by hand.

For a reason. GroupLayouts were designed for DnD type of tools and not hand coding.

Bernhard Goetz wrote: I recommend using a gui editor, like the excellent (and free!) Google WindowBuilder for Swing. Which I believe is also a good starting software to get in touch with Swing gui development in general.

Sigh! I beg to differ. Hand coding is the best. This has been discussed numerous times before. Please search the forums to understand why gui builders are a bad idea.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic