File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JPanel and LayoutManager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel and LayoutManager" Watch "JPanel and LayoutManager" New topic
Author

JPanel and LayoutManager

Tom Sakra
Greenhorn

Joined: Oct 09, 2010
Posts: 8
Hey

My program fills a panel with checkboxes dynamically and I want the panel to stretch accordingly to the amount of content,
this works fine as long as I keep the window at the same size at runtime as I do when I'm working in NetBeans. However, if I
try to maximize the window, the panel suddenly gets greedy and takes up a lot of extra space beneath the checkboxes, without
actually putting anything else in there.

Any suggestions as to how I could solve this? I've been using a BoxLayout with the vertical resizable on the aforementioned panel.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Well, you will have to decide what you do want to do with the extra space.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
if I try to maximize the window


Thats what maximizing does, it maximizes the vertical and horizontal areas.

For more help create a SSCCE that demonstrates the incorrect behaviour.
Tom Sakra
Greenhorn

Joined: Oct 09, 2010
Posts: 8
Yeah, but it doesn't maximize it completely either. It just uses about 200 pixels more than it should when I maximize the window.
So there's still room for it to stretch more, which doesn't make any sense as to why it just randomly stops, but I'd rather it stopped
stretching after the panel was filled. So is there any way to decide the size of the panel without using the vertical resizable option?

Edit:
Thanks for the help guys, but I just did what I asked for in the last line above :P Just added the preferredSize (height) of the given
checkboxes to a variable and adjusted the panel size to that variable, and using the BoxLayout with the page axis.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

If you use layout managers correctly, you should never have to adjust a size manually.

I encourage you to post a SSCCE, as Rob already asked, so others here can study it and advise you how to improve it.


luck, db
There are no new questions, but there may be new answers.
Tom Sakra
Greenhorn

Joined: Oct 09, 2010
Posts: 8
Of course not, but I find creating a relatively large GUI in NetBeans is a bit of a wrestle itself.
Since I'm using NetBeans to create the GUI, I'm pretty sure that creating that exact part
would've been easier manually. But I'm not familiar with using custom components in the NetBeans
GUI editor, so this will have to do for now. I might come back to it later if the schedule allows for it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JPanel and LayoutManager