So I have the method JOptionPane.showInputDialog() which returns a String that is the value input by the user.
The Dialog box has an OK and a Cancel button.
How can I check so that I know whether the user clicked OK or Cancel?
So I have the method JOptionPane.showInputDialog() which returns a String that is the value
Share
JOptionPane.showInputDialog()will return the string the user has entered if the user hits ok, and returnsnullotherwise. Therefore, you can just check to see if the resultant string isnull. The javadocs on the method here are not terribly explicit about this, but where the return behavior is mentioned, it is indicated to be so.