0

The item menu About of my JFrame is a JDialog that can be closed thanks to a but button as you can see below:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    aboutDialog.this.dispose();
}                                

sometimes when I click on the close button of the JDialog, it actually closes the entire program.

I tried:

aboutDialog.this.setvisible(true)
aboutDialog.this.setDefaultCloseOperation(EXIT_ON_CLOSE);
aboutDialog.this.setDefaultCloseOperation(HIDE_ON_CLOSE);
aboutDialog.this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

But it didn't worked, any ideas?

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
sina
  • 1
  • 1
  • aboutDialog.this.setDefaultCloseOperation(EXIT_ON_CLOSE)? – MadProgrammer May 07 '16 at 08:22
  • `sometimes when I click on the close button of the JDialog, it actually closes the entire program.` - this will happen if the dialog is the only open window in your application. – camickr May 07 '16 at 15:36

1 Answers1

0

Duplicate: Button for closing a JDialog {

    import java.awt.event.*;
    import javax.swing.*;

    public class YourDialog extends JDialog implements ActionListener{ 

      JButton button;

      public YourDialog() {
         button = new JButton("Close");
         button.addActionListener(this);
         add(button);
         pack();
         setVisible(true);
      }

      public void actionPerformed(ActionEvent e) {
          dispose();
      }
    }
}
Community
  • 1
  • 1