aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Simple java layout question 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 "Simple java layout question" Watch "Simple java layout question" New topic
Author

Simple java layout question

Paul Statham
Ranch Hand

Joined: Dec 05, 2008
Posts: 48
Hi Folks,

I'm still getting used to layout managers etc, I have a JPanel that is quite large in size, I'm wanting to add another panel to it that looks something like below (the contents of the frame)



However when I add this Panel to a bigger Panel, it screws it



And here's the pretty simple test code I've been using



Thanks,
Paul
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
When you add the panel to a BorderLayout the size of the component is automatcally changed to take up all the space in the BorderLayout. Since a GridLayout also expands to take up all the space all the components get resized. You can prevent this by wrapping your panel into another panel that uses a layout manager that respects the preferred size of the components. Something like this:

Paul Statham
Ranch Hand

Joined: Dec 05, 2008
Posts: 48
Rob Camick wrote:When you add the panel to a BorderLayout the size of the component is automatcally changed to take up all the space in the BorderLayout. Since a GridLayout also expands to take up all the space all the components get resized. You can prevent this by wrapping your panel into another panel that uses a layout manager that respects the preferred size of the components. Something like this:



Thanks
 
wood burning stoves
 
subject: Simple java layout question