• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

2 panels in south region

Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic