JOptionPane need help

Discussion in 'Java' started by HS1, Nov 30, 2004.

  1. HS1

    HS1 Guest

    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
     
    HS1, Nov 30, 2004
    #1
    1. Advertising

  2. HS1

    Sudsy Guest

    HS1 wrote:
    > 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.

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
     
    Sudsy, Nov 30, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SuperChuck
    Replies:
    3
    Views:
    4,091
    Sandip Chitale
    Aug 7, 2003
  2. Joseph M. DeAngelo
    Replies:
    0
    Views:
    1,112
    Joseph M. DeAngelo
    Nov 9, 2003
  3. Alex Hunsley

    thread safeness of JOptionPane et al

    Alex Hunsley, Jan 13, 2004, in forum: Java
    Replies:
    0
    Views:
    770
    Alex Hunsley
    Jan 13, 2004
  4. jazzy

    Using JOptionPane

    jazzy, Apr 18, 2004, in forum: Java
    Replies:
    0
    Views:
    376
    jazzy
    Apr 18, 2004
  5. shoa

    JOptionPane needs help

    shoa, May 13, 2005, in forum: Java
    Replies:
    4
    Views:
    3,443
Loading...

Share This Page