Jpanel not displaying

i have 2 Jpanels and at the click of a button, "a" should show up and "B" should be removed and call the validate method .now if i click another button the reverse should happen .but the panel does not show until i move my mouse on it .please what can i do?
[271 byte] By [Ladia] at [2007-11-27 7:33:12]
# 1
CardLayout
bsampieria at 2007-7-12 19:13:36 > top of Java-index,Desktop,Core GUI APIs...
# 2
Try to call the pack() mathod for your frame after you remove the first panel and add the other one.like thismyFrame.pack()regards
Ahmad_qauoda at 2007-7-12 19:13:36 > top of Java-index,Desktop,Core GUI APIs...
# 3

I think CardLayout is the better choice.

Add both panels to a component which uses the CardLayout manager, which you initialized as private member like

this.localCardLayout = new CardLayout();

this.setLayout(localCardLayout);

this.add(identifierPanelA, panelA);

this.add(identifierPanelB, panelB);

where panelA and panelB are your panels and identifierPanelA and identifierPanelB are two different strings.

Initially this will show panelA, you can easily switch to panelB by calling the following method:

this.localCardLayout.show(this,identifierPanelB);

marco@dea at 2007-7-12 19:13:36 > top of Java-index,Desktop,Core GUI APIs...
# 4
can't observe any difference i think i should call the validate method but i am not having effect
Ladia at 2007-7-12 19:13:36 > top of Java-index,Desktop,Core GUI APIs...
# 5

if you post some code it would be easier to track down your problem.

Nevertheless i recognized that i used a function call which may result in deprecated method in my example. Instead of

this.add(identifierPanelA, panelA);

this.add(identifierPanelB, panelB);

you should use

this.add(panelA, identifierPanelA);

this.add(panelB, identifierPanelB);

marco@dea at 2007-7-12 19:13:36 > top of Java-index,Desktop,Core GUI APIs...
# 6
> i think i should call the validate method I think you should use the Card Layout as has been suggested before. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html]How to Use Card Layout[/url] for a working example.
camickra at 2007-7-12 19:13:36 > top of Java-index,Desktop,Core GUI APIs...