Java Dialog – Find out if OK is clicked?

I’d suggest to use showConfirmDialog instead

int result = JOptionPane.showConfirmDialog(myParent, "Narrative", 
       "Title", JOptionPane.INFORMATION_MESSAGE);

and there you can test for various returns value from JDialog/JOptionPane

if (result == JOptionPane.OK_OPTION, 
              JOptionPane.CANCEL_OPTION, 
              JOptionPane.CLOSED_OPTION, etc..

Leave a Comment