Hi! Please, tell me how to make the JDialog close button working in a proper way. Now it does not work. System.out.println(value);
produces 0. But if I write if (value == 0)
, then nothing happens. Any ideas? Thanks!
public static void about() {
final JOptionPane optionPane = new JOptionPane(
"Some info",
JOptionPane.PLAIN_MESSAGE,
JOptionPane.CLOSED_OPTION);
final JDialog dialog = new JDialog((JDialog)null,"Hello",true);
dialog.setContentPane(optionPane);
dialog.setDefaultCloseOperation(
JDialog.DISPOSE_ON_CLOSE);
dialog.pack();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Dimension screenSize = toolkit.getScreenSize();
final int x = (screenSize.width - dialog.getWidth()) / 2;
final int y = (screenSize.height - dialog.getHeight()) / 2;
dialog.setLocation(x, y);
dialog.setVisible(true);
int value = ((Integer)optionPane.getValue()).intValue();
System.out.println(value);
if (value == JOptionPane.CLOSED_OPTION) {
dialog.dispose();
}
}