Get return value of JOptionPane

My JOptionPane code is as follows:

selectedSiteName = JOptionPane.showInputDialog("Enter the name of the new site:"); 

This displays input with a text box and an OK and Cancel button. I need to determine if Cancel was clicked.

Greetings.

+6
java joptionpane
source share
3 answers

Check if selectedSiteName == null.
This will happen if the user clicks Cancel or closes the dialog.

+12
source share

Read the JOptionPane API and follow the link to the Swing turorial on How to Use Dialogs for a working example.

0
source share
 if(selectedSiteName == JOptionPane.CANCEL_OPTION) { } 

must work.

0
source share

All Articles