Skip to content

Instantly share code, notes, and snippets.

@Vzor-
Created September 22, 2022 16:44
Show Gist options
  • Save Vzor-/ad2d18bfda4bcdc6b6915851dcace76c to your computer and use it in GitHub Desktop.
Save Vzor-/ad2d18bfda4bcdc6b6915851dcace76c to your computer and use it in GitHub Desktop.
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
public class DialogTest {
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
final JDialog dialog = new JDialog((Frame)null,
"Close me",
true);
dialog.setSize(200, 100);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
JOptionPane.showMessageDialog(null, "Are you sure?");
// Uncomment to fix issue
// try {
// Thread.sleep(500);
// } catch (InterruptedException ex) {
// throw new RuntimeException(ex);
// }
}
});
SwingUtilities.invokeAndWait(() -> dialog.setVisible(true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment