• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

2 panels in south region

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
upperBottomPanel = new ImagePanel(img);
upperBottomPanel.setLayout(null);

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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic