I am buliding an NetBeans Platform application. When the user clicks on the X of the main window I want the application to do nothing and show a password JDialog. If the password is correct close the app, else do not close the app. How do I do this? I’ve created a Listener class that will show the password JDialog, but how do I stop the application from closing? Similar to JFrame’s setDefaultCloseOperation, and setting it to do nothing on close.
public class Listener extends WindowAdapter {
private Frame frame;
@Override
public void windowActivated(WindowEvent event) {
frame = WindowManager.getDefault().getMainWindow();
frame.setSize(946, 768);
}
@Override
public void windowClosing(WindowEvent event) {
ShutDownMainWindowJDialog shutDownMainWindowJDialog;
shutDownMainWindowJDialog = new ShutDownMainWindowJDialog(null, true);
shutDownMainWindowJDialog.exeShutDownMainWindowJDialog();
shutDownMainWindowJDialog.setLocationRelativeTo(frame);
shutDownMainWindowJDialog.setVisible(true);
}
}
public class Installer extends ModuleInstall {
@Override
public void restored() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Frame frame = WindowManager.getDefault().getMainWindow();
frame.addWindowListener(new Listener());
}
});
}
}
It is easy. So create module with installer and overwrite method closing (may by), then show your dialog and return false (not close app). Jirka
So this is conclusion:
add to your module installer/activator
Jirka