File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes 2 panels in south region Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "2 panels in south region" Watch "2 panels in south region" New topic

2 panels in south region

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 191


I have a JPanel using the BorderLayout containing a JPanel in the NORTH region and a JPanel in the SOUTH region. This JPanel in turn is contained in the SOUTH region of my JFrame. Sometimes when I start the program I only see one of the two panels, but when the mouse is moved a few times the other panel pops into view and the rest of the program layout shifts in accordance and is seen as I have intended. I have tried a number of things such as using setPreferredSize() but the same thing keeps happening, mind you it does not happen at every startup. Any hints as to how I might resolved this annoyance is well appreciated. Thanks.

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
upperBottomPanel = new ImagePanel(img);

When you add components to a container the parent components (container) layout manager asks each of the children for their size requirements and makes arrangements to show each component according to its needs. Some layout managers practically ignore the size requirements of the child components, eg, GridLayout. Some layout managers pay special attention to the preferred size of the child components and attempt to show them at this size. Other layout managers fall in between these extremes. All is documented in the class api for the layout managers and in the tutorial pages on layout managers.
When you specify null for a layout manager then you must supply the layout information to the parent container so it knows what to do with the children you have added to it. We do this with setBounds and setLocation. After realization setSize also works.
The preferredSize is useful for layout managers that honor it in Swing and in j2se 1.5+ in the AWT.
Your choices are to either use one or a combiation of layout managers, or to specify bounds for each of the components that you want shown in containers with null layout managers.
To learn about layout managers see Lesson: Laying Out Components Within a Container.
I agree. Here's the link:
subject: 2 panels in south region
It's not a secret anymore!