Get the return value of JOptionPane

burntsugar picture burntsugar · Aug 1, 2009 · Viewed 11.2k times · Source

My JOptionPane code is as follows:

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

This renders out an input with a textbox and an OK and Cancel button. I need to detect if Cancel was clicked.

Cheers.

Answer

Jataro picture Jataro · Aug 1, 2009

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