Problem: Refreshing a JPanel only works when I resize the window

Hello,

Here is my problem when I click on my a button I want the component in my Jpanel (JLabel and JtextField) to disappear and add some other one.

I do that by using :

1) the methodremoveAll() on my JPanel

2) add my new JLabel and JtextField to my JPanel

3) usingrepaint() andrevalidate()

Actually it works the first time, but then I have to resize my GUI window, even a litte for my new components to appear.

I think the problem comes from removeAll() method. So if anyone has an idea how I can refresh a JPanel (removing old components and adding new ones) without resizing the window it would be nice.

Thank you.

[699 byte] By [bastrala] at [2007-11-27 8:12:37]
# 1
Calling revalidate should work.You can try: (AWT method)invalidate();validate();orrevalidate(); (Swing method)orJPanel p = ...; // your
rkippena at 2007-7-12 19:57:01 > top of Java-index,Desktop,Core GUI APIs...
# 2

The order should be revalidate() and then sometimes you also need repaint().

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-12 19:57:01 > top of Java-index,Desktop,Core GUI APIs...