1

I have 3 panels in the frame, panel, panel1, panel2. When I click on the button it doesn't remove the panel from the frame.

private class ButtonListener implements ActionListener
{
    public void actionPerformed (ActionEvent e)
    {
         // some stuffs here.
          ++current;
           frame.remove(panel1);
          frame.revalidate();
          frame.repaint();
      }     
 }

edit: i used this too but it doesn't work as well

          frame.remove(panel1);
          frame.getContentPane().invalidate();
          frame.getContentPane().validate();
          frame.getContentPane().repaint();
june
  • 19
  • 2
  • 5
    For many components in one space, use a [`CardLayout`](http://docs.oracle.com/javase/7/docs/api/java/awt/CardLayout.html) as see in this [short example](http://stackoverflow.com/a/5786005/418556). – Andrew Thompson May 16 '13 at 12:14
  • I do not understand the question. Maybe showing us a little more code and explaining what you want it to do and what it actually does, could help... – gkalpak May 16 '13 at 12:14
  • 2
    *"I googled about this, using frame.getContentPanel()"* Given there is no such method I'm not surprised your searches were fruitless. Probably the only site offering Java help that would make that mistake is RoseIndia.. – Andrew Thompson May 16 '13 at 12:17
  • 2
    @june, [sscce](http://www.sscce.org). – mre May 16 '13 at 12:30
  • JFrame.remove(comp) : "This will do nothing if comp is not a child of the JFrame or contentPane". – Jool May 16 '13 at 15:08

0 Answers0