views:

471

answers:

3

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.

+5  A: 

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

Jataro
A: 

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

camickr
A: 
if(selectedSiteName == JOptionPane.CANCEL_OPTION)
{


}

should work.

Nick Gibson