How do I remove an old JPanel and add a new one?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-03-21T15:53:15Z Indexed on 2010/03/21 16:01 UTC
Read the original article Hit count: 164

Filed under:
|
|
|
|

I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it?

I tried the following:

public static void showGUI() {
    JFrame frame = new JFrame("Colored Trails");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
    frame.add(partnerSelectionPanel);
    frame.setSize(600,400);
    frame.setVisible(true);
}

private static void updateGUI(final int i, final JLabel label, final JPanel partnerSelectionPanel) {
    SwingUtilities.invokeLater( 
        new Runnable() {
            public void run() {
                label.setText(i + " seconds left.");
            }
            partnerSelectionPanel.setVisible(false); \\ <------------
        }
    );
}

So, my code update the "old" JPanel and them it makes the whole JPanel invisible. It was the idea. But it does not work. The compiler complains about the line indicated with "<------------". It writes: <identifier> expected, illegal start of type.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing