adding or removing panels to panels
Hi everyone, I need help with JPanel
I have a panel named "contentPanel" inside of a Main Frame and I am inserting to that panel another JPanel "MyPanel" from another class with add.()
Quote:
contentPanel.setLayout(new BorderLayout(5, 5));
contentPanel.add(MyPanel, BorderLayout.CENTER);
What I want is to hide that new panel inserted (MyPanel) and insert or show another on top of it, that means I have contentPanel that has MyPanel but in an exact moment, I want it to change to OtherPanel for example (OtherPanel is a panel from another class).
If I do add() with the new panel, it appears in top of MyPanel and all the components from both panels show up, and dont work.
Thanks and hope you understand my english.
Re: adding or removing panels to panels
Re: adding or removing panels to panels
Can't u just set it to trigger setVisible(true) or false?
Re: adding or removing panels to panels
Quote:
Originally Posted by
macko
Can't u just set it to trigger setVisible(true) or false?
Not necessarily, since he's adding the second JPanel to the first. He wants the first one to go away, but setting it to invisible would also cause the second one to become invisible. CardLayout is the solution to this.