Closing java program properly when JDialog is the main window

I have JDialog as the main window in my application (originally it was a JFrame, but it displayed in the taskbar, which I don't need).

I am currently doing:

setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

and when I press the exit button:

frame.dispose();

But the process still seems to be hanging in the background

JFrame had JFrame.EXIT_ON_CLOSEthat seemed to do what I wanted.

How can I close the application correctly?

+5
source share
6 answers

You can add

  System.exit(0);

where you want to end the program, possibly right after the dispose () line.

+6
source

WindowListener, System.exit(0), .

JDialog dialog = ...;
dialog.addWindowListener(new WindowAdapter() { 
    @Override public void windowClosed(WindowEvent e) { 
      System.exit(0);
    }
  });

, System.exit(0) "" ( ) - .

+11

JWindow (un-decoretad by defalut), , JWindow JFrame ( , )

WindowListener, / /

+3

, EXIT_ON_CLOSE JDialog, ?

@camickr, EXIT_ON_CLOSE setDefaultCloseOperation JDialog. API,

, , "" . :

  • DO_NOTHING_ON_CLOSE ( WindowConstants): ; , windowClosing WindowListener.
  • HIDE_ON_CLOSE ( WindowConstants): WindowListener.
  • DISPOSE_ON_CLOSE ( WindowConstants): WindowListener.

EXIT_ON_CLOSE , IllegalArgumentException.

+1

windowClosing:

dialog.addWindowListener(new WindowAdapter() 
                @Override
                public void windowClosing(WindowEvent e) {
                     System.exit(0);
                }
    });
0

-

JDialog dialog = (JDialog) container;
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setModal(false);
dialog.setVisible(false);
dialog.dispose();

Runtime.getRuntime().exit(1);

, JDialog, , JDialog JFrame JDialog, , JDialog , , .

0

All Articles