I created an applet where, when you click the "Forgot Password" button, I delete the current JPanel on the applet and create a new JPanel that displays the JComponents associated with receiving / forgetting the password.
I can successfully clear JPanel using .removeAll (); BUT, after I create all my new JComponents and add them to the content panel (main JPanel), the applet just saddles and does not display the new JPanel and UNLESS components . resize the applet, then it repaints and works.
I tried putting .invalidate () after I created all new JComponents, but which still does not update the applet?
How can I create my JPanel after cleaning it with .removeAll () and add different JComponents to it?
The code:
public class App extends JApplet
{
JPanel mainPanel;
public void init()
{
SwingUtilities.invokeAndWait( new Runnable() {
public void run()
{
showLoginPanel();
}
});
}
public void showForgotPassPanel()
{
mainPanel.removeAll();
mainPanel = (JPanel) getContentPane();
Box hBox = Box.createHorizontalBox();
Box vBox = Box.createVerticalBox();
mainPanel.setLayout( new BorderLayout() );
... create components
... add components to mainPanel
mainPanel.invalidate();
}
}
source
share