• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Switching JPanels

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my program a certain JPanel changes as the user changes between JDialogs.
To remove the panel, I am calling remove() within the JPanel containing it, giving a reference to the JPanel that is being removed. This seems to work fine.
Then, to add the new JPanel, I call add() and pass in a reference to the new JPanel and its position (BorderLayout.CENTER).
The problem is that this new panel does not show until I resize the overall JFrame containing it. This strikes me as a very strange problem. Is there a method I need to call when changing JPanels in this manner?
Thanks,
Daniel
[This message has been edited by Daniel Searson (edited March 06, 2001).]
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,
You need to add following two lines to your code after u add new JPanel to it.

here fr is the container to which you are adding /removing panels

hope this helps.
regards
deeksha


 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't a card layout be better for what you are trying to do?
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks deeksha! The code you gave worked perfectly.
Bodie: For what I doing, the BorderLayout is working fine. The dialogs that are being switched are actually editable and the panel needs to change to reflect the dialog being edited...
Daniel
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am did the same exact thing as the original posting, but when the new panel goes out of focus, it doesn't get repainted when it comes back in. For example, if I minimize it and bring it back, it's gone. How do I solve that? Thanks.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try doing a validate() and then a repaint(). That's been working in my code.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Use CardLayout it is much faster and easier and everything that it should be and u can make visible different panels by calling the methods provided by cardlayout from a menu or a button!!
amol
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic