0

I have a small problem: I created a JFrame and I added others components in there. Among these components there is a JButton called deletme. I want to when I click that deletme button the frame stays there but only its components go away. I wrote this as a trick:

   deletme.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent arg0) {
      dispose();
      aaa x=new aaa();} 

( aaa inherits from JFrame and it looks exactly like the Class JFrame I'm working on but the only difference is that it's without components). but this makes it clear the the frame is closed and reopened again. Guys is there any solution to make it work?!

[sorry for my bad english}

Abdelaziz Dabebi
  • 1,624
  • 1
  • 16
  • 21
  • Why don't you just remove the components from the JFrame? Or simply set them to invisible? – Kevin Workman Jul 16 '14 at 16:32
  • Oh do you mean I should delete them one by one? and actually after I click the deletme button there are new components to be placed there but I didn't want to mention that. – Abdelaziz Dabebi Jul 16 '14 at 16:35
  • Or just remove the JPanel they're all in. There are also handy methods in the Container class that return all of its children. – Kevin Workman Jul 16 '14 at 16:36
  • A few tips: 1) Look at this [article](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice/9554657#9554657) about using multiple JFrames AND 2) if `aaa` is a class then it should be `Aaa` (look at capital letter) AND 3) Make the class `aaa` something more related to what it does :) and well you've got the answer to your question... don't forget to accept it. – Frakcool Jul 16 '14 at 17:01

1 Answers1

2

In your actionPerformed, all you have to do is:

getContentPane().removeAll();
repaint();
sgbj
  • 2,264
  • 17
  • 14