views:

59

answers:

1

I have created in Java swing an option dialog with the JOptionPane.showOptionDialog method. This dialog includes different buttons, and among those a Cancel button. I would like to attach a listener method to this Cancel button so that once selected, the dialog is disposed.

My question is: how do I "retrieve" (or return) the dialog generated by the JOptionPane.showOptionDialog method?

+3  A: 

I will assume you have read "How to Make Dialogs" tutorial from Oracle?

The return value from showOptionDialog() is an int, which indicates which button was chosen. Regardless of pressing OK, cancel or whatever, the window should dispose of itself. If you need more information back from the window then just which button was pressed, look at the other options like showInputDialog().

Sean
@Tony: There's a related example here: http://stackoverflow.com/questions/3002830
trashgod