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 Simple java layout question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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: 40
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: 2153
    
    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: 40
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple java layout question
 
Similar Threads
Help with basic gui problem
Inserting an Image in JTextField
Need help
Need help with Layout
JTextArea scroll bar