not best practices, not preferred way, only to close current JVM instance and very simple,
1) Top-LevelContainer#setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
2) add WindowListener
WindowListener exitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(null,
"Are You Sure to Close Application?", "Exit Confirmation",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
Top-LevelContainer#setVisible(false);
// clean-up everything
// on error display JOptionPane with error mgs but from
// another JVM instance, e.g.jar file, see add 3.)
System.exit(1); //in some cases not works System.exit(0);
}
}
3) here is rest for how to display error message from another, new JVM instance