JOptionPane need help

H

HS1

Hello all
I want to show a dialog asking users to select a string. They also can
Cancel if they want to cancel the input.
Here is the code for a JOptionPane:

Object[] possibleValues {"First", "Second", "Third"};
Object selectValue = JOptionPane.showInputDialog(null, "Choose one", "Input
value", JOptionPane.OK_CANCEL_OPTION, null, possibleValues,
possibleValues[0]);

if (selectValue != null){
" ...Do Something..."
}

It can be seen that the dialog has two button: OK and Cancel. However the
cancel button does not work as when I click Cancel, my application still
"...Do Something..."


Could you please help to fix this
Many thanks
SH1
 
S

Sudsy

HS1 said:
Hello all
I want to show a dialog asking users to select a string. They also can
Cancel if they want to cancel the input.
Here is the code for a JOptionPane:

Object[] possibleValues {"First", "Second", "Third"};
Object selectValue = JOptionPane.showInputDialog(null, "Choose one", "Input
value", JOptionPane.OK_CANCEL_OPTION, null, possibleValues,
possibleValues[0]);

if (selectValue != null){
" ...Do Something..."
}

I haven't said this in a long time, but RTFM.
Here's an extract from the javadocs:

"static int OK_CANCEL_OPTION
Type used for showConfirmDialog."

And further down:

"showInputDialog
...
messageType - the type of message to be displayed: ERROR_MESSAGE,
INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE"

You'd get answers quicker by reading the documentation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top