View Single Post
Old 04-14-2003, 08:46 AM   #12 (permalink)
jeff
Registered User
 
Join Date: Apr 2003
Posts: 2
jeff is on a distinguished road
Hi,

Notice that when you first add your button, you're adding it to the JFrame's content pane. The content pane is where you're supposed to add components to a JFrame.

see:
http://java.sun.com/docs/books/tutor.../toplevel.html

Later in your application, you're calling removeAll directly on the JFrame. This removes the content pane and other panes mentioned in the above URL. You don't really want to be doing this. Instead, call getContentPane().removeAll(). This will restore the JFrame back to how it was before you added any components.

Then, add your new components to the content pane and call:

invalidate
revalidate
repaint

on it.

So, the body of your actionListener could look like this:

xFrame.getContentPane().removeAll();
xFrame.getContentPane().add(new JLabel("Java is NOT stupid"));
xFrame.getContentPane().invalidate();
xFrame.getContentPane().validate();
xFrame.getContentPane().repaint();

I've tried this with your code and it fixes the problem.
jeff is offline   Reply With Quote