I have created an applet where when you press the button "Forgot Pass" I erase the current JPanel on the applet & create a new JPanel that displays the JComponents related to Retrieving/Forgetting a password.
I can successfully clear the JPanel using .removeAll(); BUT after I create all my new JComponents & add them to the content pane (main JPanel) the applet just goes gray & doesn't show the new JPanel & components UNLESS I resize the applet, then it repaints & works.
I have tried putting .invalidate() after I have created all the new JComponents but that still doesn't refresh the applet?
How can I make my JPanel appear after I clear it with .removeAll() & add different JComponents to it?
Code:
public class App extends JApplet
{
JPanel mainPanel;
public void init()
{
SwingUtilities.invokeAndWait( new Runnable() {
public void run()
{
showLoginPanel(); // this shows fine on loading
}
});
}
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(); // doesn't make new layout visible, not unless I resize the applet
}
}
Use mainPanel.revalidate();
and/or mainPanel.repaint();
methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With