JOptionPane.showInputDialog cancel brings up a blank box

String name = JOptionPane.showInputDialog(
    null,
    "My message",
    "My title",
    null,
    null,
    null)  // real list of options deleted for brevityThis works okay, but when I press the cancel button, I get a blank warning JOptionPane (message box thingy)... how do I tailor the message in that? Been looking through the search results and API with little luck.

handle it like so
try
    String s = new JOptionPane.showInputDialog(null, "Enter input");
catch(Exception ee)
    JOptionPane.showMessageDialog("Invalid input");
}

Similar Messages

  • JOptionPane.showInputDialog and the cancel button

    so i'm using a JOptionPane.showInputDialog, and everything works except when i click the cancel button to exit the window, it gives me an error.
    how can i remedy this?
    here's a section of my code: (a is an array, as is b)
    firstWord = JOptionPane.showInputDialog
    ("What company's sloagan is/was: "+a[count]+"?");
    if(firstWord.equalsIgnoreCase(b[count]))
    JOptionPane.showMessageDialog (null,
    "Thats Right, the company was "+b[count]+".");
    count++;
    int YesNo = JOptionPane.showConfirmDialog (null,
    "Do you want to play again?", "Choose One", JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
    if(YesNo==1) //this should exit out if you click no
    System.exit (0);
    if(count==10)
    JOptionPane.showMessageDialog(null,
    "Game Over. You Won.");
    System.exit (0);
    else
    JOptionPane.showMessageDialog (null,
    "Sorry, you aren't that smart. Guess again.");
    }]

    1- Seems like you misstyped your code tags...
    2- When you say: "it gives me an error", please provide details (e.g. stack trace)
    3- Read the API doc, it says: showInputDialog returns user's input, or null meaning the user canceled the input.
    So firstWord.equalsIgnoreCase(b[count]) will throw a NullPointerException in that case.
    You might check for null value.
    Note:str1.equals(str2) will throw a NullPointerException when str1 is null, but str2 can be null without a NullPointerException being thrown:String str1 = null;
    String str2 = "toto";
    System.out.println(str1.equals(str2)); // NullPointerException
    System.out.println(str2.equals(str1)); // ok (prints false)

  • JOptionPane.showInputDialog without CANCEL Button

    How can I do a JOptionPane.showInputDialog without CANCEL Button.
    Besides if I press OK without tyoing anything, will a null String but returned?
    Thanks

    I don't think you can with an Input Dialog. Normally, you want to give the user a chance to cancel the operation. Here is an example using a Message Dialog. After the user hits OK, you can get the text from the text field.          JPanel p = new JPanel(new GridLayout(2,1));
              JTextField t = new JTextField();
              JLabel l = new JLabel("A message");
              p.add(l);
              p.add(t);
              JOptionPane.showMessageDialog(null,p,"Title",JOptionPane.PLAIN_MESSAGE);

  • JOptionPane.showInputDialog and Focus

    I have a program that allows the user to type in a String in a text box and when they hit the enter key the text will appear in a text area. I've also added a menu bar to the program. When the user clicks on File and then Connect from the menu bar I want a JOptionPane to pop up that asks for the user to type in a username and then prompt for a password. And I've gotten all of that to work. Now for the problem. I click on file from the menu bar and then connect and it prompts me for the username as it should. I am able to just type in a phrase in the text field of the username dialog box and hit the enter key and then it prompts me for my password. I am still able to type in a phrase in the text field of the password Dialog box, however when I hit the enter key, the Dialog box does not close as it did for the username Dialog box. It will still close if I click on the OK button, but just pressing the enter key does not close the Dialog box as it did when it prompted for a username. I'm thinking I need to direct the focus to the password dialog box, but not sure how to go about doing this. Any help in solving this problem would be greatly appreciated.
    Here is my code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class TestJOptionPane extends JFrame implements ActionListener{
         private static int borderwidth = 570;
         private static int borderheight = 500;
         private JPanel p1 = new JPanel();
         private JMenu m1 = new JMenu("File");
         private JMenuBar mb1 = new JMenuBar();
         private JTextArea ta1 = new JTextArea("");
         private JTextField tf1 =new JTextField();
         private Container pane;
         private static String s1, username, password;
         private JMenuItem [] mia1 = {new JMenuItem("Connect"),new JMenuItem("DisConnect"),
              new JMenuItem("New..."), new JMenuItem ("Open..."), new JMenuItem ("Save"),
              new JMenuItem ("Save As..."), new JMenuItem ("Exit")};
    public TestJOptionPane (){
         pane = this.getContentPane();
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
         dispose();
    System.exit(0);
         setJMenuBar(mb1);
    mb1.add(m1);
    for(int j=0; j<mia1.length; j++){
         m1.add(mia1[j]);
    p1.setLayout( new BorderLayout(0,0));
    setSize(borderwidth, borderheight);
    pane.add(p1);
              p1.add(tf1, BorderLayout.NORTH);
              p1.add(ta1, BorderLayout.CENTER);
              this.show();
              tf1.addActionListener(this);
              for(int j=0; j<mia1.length; j++){
                   mia1[j].addActionListener(this);
         public void actionPerformed(ActionEvent e){
              Object source = e.getSource();
              if(source.equals(mia1 [0])){
                   username = JOptionPane.showInputDialog(pane, "Username");
                   password = JOptionPane.showInputDialog(pane, "Password");
              if(source.equals(tf1)){
                   s1=tf1.getText();
                   ta1.append(s1+"\n");
                   s1="";
                   tf1.setText("");
         public static void main(String args[]){
              TestJOptionPane test= new TestJOptionPane();
    }

    But using JOptionPane doesn't get the focus when you call itworks ok like this
    import javax.swing.*;
    import java.awt.event.*;
    class Testing
      public Testing()
        final JPasswordField pwd = new JPasswordField(10);
        ActionListener al = new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            pwd.requestFocusInWindow();}};
        javax.swing.Timer timer = new javax.swing.Timer(250,al);
        timer.setRepeats(false);
        timer.start();
        int action = JOptionPane.showConfirmDialog(null, pwd,"Enter Password",JOptionPane.OK_CANCEL_OPTION);
        if(action < 0)JOptionPane.showMessageDialog(null,"Cancel, X or escape key selected");
        else JOptionPane.showMessageDialog(null,"Your password is "+new String(pwd.getPassword()));
        System.exit(0);
      public static void main(String args[]){new Testing();}
    }

  • JOptionPane.showInputDialog

    Hi,
    I have a question about JOptionPane.showInputDialog(...), there is a method that accepts an object array for its parameter, when the array size exceeds a certain bound the final dialog will contains a JList in it. When I click the item of the JList then click cancel the null will be returned, but when double clicking item and then cancel the item will be returned. Partial of my code is:
    String[] available = toSortedStringArray(mapColumn.keys());
    if (available.length == 0)
         return;
    Object selected =
         JOptionPane.showInputDialog(
              FilterControl.this,
              "Select Column",
    JOptionPane.QUESTION_MESSAGE,
              null,
              available,
              null);
    if (selected != null)
    When the dialog shows, double click one of the items in the JList and then click cancel, the selected will be the item, that's what we unexpected, the null returned will be expected.
    Who can help giving a hint about how to solve this problem?
    PS: One of the solutions is don't call this static method but write our own code or to create a class to extend the JOptionPane, but I think it is ineffective.

    It's a bug:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6428694

  • Blank boxes when I insert question slides.

    I posted this yesterday and no one replied... Hopefully
    someone can give me some advice. Thanks!!
    I am trying to create a new project in CP3 and once I publish
    the project, there are 2 blank boxes on each slide and the movie
    stops on the second slide. These projects consist of 8 PPT slides,
    7 image slides, and 5 questions slides... and this project is
    narrated. I have tried creating the project again hoping the blank
    boxes would go away and that didn't work. So I published this
    module one slide at a time to try and determine the root of the
    problem. I can publish all 15 slides of images and PPT as a SWF
    file with no problem. But once I insert question slides, that's
    when the blank boxes appear and the module stops on slide 2. I
    think this is odd considering my question slides are the last 5
    slides of the module but the blank boxes start on slide one. When
    previewing each slide, each 5 slides, or the entire project, there
    are no problems. It's just once I publish the project. I've tried
    publishing to SWF file and a stand alone disc.. same problem. I
    also tried bringing up a module I had done before on CP1 and
    converted the files, made no changes to the project and just
    published it with CP3 as SWF file. I got the blank boxes and the
    project stopped at the second slide. The question slides I have are
    simple T/F or multiple choice slides and I don't have them set up
    to record results.
    Any ideas what I'm doing wrong? I've published about 25 of
    these modules in CP1 and never had this problem in the past. I
    would be happy to send someone an example of what I'm talking
    about.
    Thanks!
    Mindy Wilson
    Training Coordinator
    TALX Corp

    Thanks for responding. No, I don't have any interaction on
    the project. I even tried to create a new project and inserted 2
    PPT slides (with text only) and then one question slide... I just
    made up a simple T/F question just to have a question slide in that
    project and once I published it, it happened again. If I deleted
    that question slide and published, the blank boxes were gone and it
    didn't freeze up.
    I was on the phone all morning with Adobe support and they
    suggest I reinstall the software. All software disks for my company
    are located at home office so once I receive the software tomorrow,
    I'll try it again. If that doesn't work, I'll certainly appreciate
    any help.
    Thanks!

  • JOptionPane.showInputDialog Help!!!!

    Hello,
    I'm using JOptionPane.showInputDialog(Component parentComponent,
    Object message,
    String title,
    int messageType,
    Icon icon,
    Object[] selectionValues,
    Object initialSelectionValue ).
    which prompts the user to add some text and the same will be stored for later retrieval.
    In this case, JOptionPane pops up with a label, textfield,OK & Cancel buttons.
    Default focus is given to to the TextField.
    Is there anyway to get access to the TextField via code ?
    For example, if the user types "Hello World" in the given TextField, then I need to get the Text entered in
    the TextField in the following manner.
    String myStr = myJOptionPaneTextField().getText();
    System.out.println("Entered Text is "+ myStr);
    How can I Achieve the same ?
    Thanks in advance
    Regards
    vargav

    Why? At what point do you know you should manipulate the text? Usually, it would be when the user clicks OK, at which point it doesn't matter because the dialog is dismissed. So what kind of operations do you expect to be able to do?
    Aside from that, I'm not sure how to get the text field in the option pane, per se... It can be gotten by digging thru the pane's components til you find a text field. But you'd need to do that in a separate thread. So it's not really feasible to do that.... There is an alternative:
    The message is an object, and it can be an array of objects, which will all be added, and thus can include a message string and a text field...
    JTextField myfield = new JTextField();
    Object[] obj = new Object[2];
    obj[0] = "Enter some text here:";
    obj[1] = myfield;
    if(JOptionPane.showOptionDialog(obj, "Enter Text", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
       String value = myfield.getText();
    }Then you can do whatever you want with the text field... but the same problem is there, you have lost the dialog before you can do anything.

  • HELP --JOPtionPane.showInputDialog

    I was developing a employee information system in swing.
    On the way of development,the major problem the is occuring
    is that two JOPtionPane.showInput Dialog boxes are appearing
    at a time.When I fetching the data to the JOPtionPane.showInput Dialog box and then clicking the "ok" option button,another JOPtionPane.showInput Dialog box appears making the program difficult to
    bug.
    Please suggest ways to solve this bug.

    It is more likely that your program has logical errors, just search for all JOptionPane.showInputDialog(...) statements and insert a println statement before it to trace the source of the problem.
    Visual Paradigm - http://visual-paradigm.com/

  • How to customize JOptionPane.showInputDialog?

    Is there a way to change the text on the ok- and cancel buttons in the JOptionPane.showInputDialog()?
    I'm trying to make the input dialog display Norwegian text in the OK and Cancel buttons, but it seems impossible...?
    None of the JOptionPane.showInputDialog methods take the options-array as input, and none of the JOptionPane constructors let me create a input dialog.
    Does anyone know how this can be done, or do I have to write my own InputDialog?

    You can get a partial list of the properties from the UIDefaults Hashtable returned by UIManager.getDefaults(), but for the rest you have to look at the source code. For example, I got this from the source code of BasicOptionPaneUI.          } else if (type == JOptionPane.OK_CANCEL_OPTION) {
                        defaultOptions = new ButtonFactory[2];
                        defaultOptions[0] = new ButtonFactory(
                            UIManager.getString("OptionPane.okButtonText",l),
                            getMnemonic("OptionPane.okButtonMnemonic", l),
                            (Icon)DefaultLookup.get(optionPane, this,
                                              "OptionPane.okIcon"), minimumWidth);
                        defaultOptions[1] = new ButtonFactory(
                            UIManager.getString("OptionPane.cancelButtonText",l),
                            getMnemonic("OptionPane.cancelButtonMnemonic", l),
                            (Icon)DefaultLookup.get(optionPane, this,
                                              "OptionPane.cancelIcon"), minimumWidth);db

  • Question about JOptionPane.showInputDialog

    How do I know when the CANCEL button is pressed in response to JOptionOptionPane.showInputDialog?
    Thanks for the help!

    Try this
    import javax.swing.JOptionPane;
    class TestJOptionPane
      public TestJOptionPane()
        String response = JOptionPane.showInputDialog("enter something");
        if(response == null) JOptionPane.showMessageDialog(null,"cancel/escape or 'x' selected");
        else if(response.equals("")) JOptionPane.showMessageDialog(null,"OK button, but nothing entered");
        else JOptionPane.showMessageDialog(null,"OK button, you entered "+response);
        System.exit(0);
      public static void main(String args[]){new TestJOptionPane();}
    }

  • JOptionPane showInputDialog Buttons

    hi
    I want to remove the cancel button from the showInputDialog? Is it possible
    Here is my code.
    String sRoleSelect = (String) JOptionPane.showInputDialog(frame, "Please Select Role",
    "dialog", JOptionPane.ERROR_MESSAGE, icon, rolelist
    .toArray(), 1);
    Thanks

    i created JOptionPane and customized to remove the buttons.

  • Why can't I print embedded images in a Thunderbird E-mail? I just get blank boxes for the images.

    I am a copyeditor who receives feedback from my clients re: manuscripts I have edited. They will often sent e-mails that include small screen captures from parts of their style guide or screen captures of the proof that is in question (small sections, like a paragraph or an equation, or a header that needs to be coded/styled differently for HTML). Now, I can see these fine in the e-mail, but when I go to print them out for my reference binder, the embedded images don't print.
    Mozilla, I need these to print; they are quite important to my job.
    To keep my e-mail from becoming too bloated, I save these important style issue e-mails into a folder on my desktop I call "Print out for binder", queuing them for the day I can print a bunch of them out and arrange them according to subject matter.
    Problem is, they are useless if they don't include these illustrative screen captures; blank boxes are worthless to the context.
    It is not my printer that is the problem. if I receive a Word doc with these screen captures, they print fine. But if I try to print from T-Bird, no go. Help. (I can't save these e-mails as Word docs either, which might solve the problem; the only options in T-Bird are "Save as file" or "Save as template".)
    Thunderbird is a powerful e-mail program, and one I have been using for over a decade. Why can't it perform this function? Please help. Or point me to an add-on. I haven't been able to find one that addresses this seemingly straightforward, common, and simple problem.

    When you select File(or AppMenu/Print)/Print Preview, do the images appear? Do the images print if you check 'Print background (colors & images)' under File/Page Setup? I don't have any problems printing a message with an embedded image, at least to an xps file.
    I devised a workaround that might help, failing a real solution: install [https://addons.mozilla.org/en-US/thunderbird/addon/unmht/ unMHT] in both TB and Firefox, and then File/Save As MHT in TB. Open the mht file in Firefox, and Print.

  • Having big problems with my new Mac Pro, when I launch Photoshop CC, I get an error message, can carry on but after a few tasks it starts going gar... menus go blank, when you try to save it shows a blank box.... can anybody help?

    Having big problems with my new Mac Pro, when I launch Photoshop CC, I get an error message, can carry on but after a few tasks it starts going gar... menus go blank, when you try to save it shows a blank box.... can anybody help?

    when I launch Photoshop CC, I get an error message
    and what exactly is the text of that error message?

  • How can I access the savestore.js contents if the command about:sessionrestore shows a blank box even for already succesfully used backups?

    -------------------------------------------------------------------------------------------------------------------------------------------
    How can I access the savestore.js contents if the command about:sessionrestore shows a blank box even for already succesfully used backups?
    Is there a recent known problem with the about:sessionrestore command or is there any other way understandable to Firefox 29.0.1 through which recover the information stored in the sessionstore.js files.
    It seems the command about:sessionrestore is not capable anymore to read the contents of the sessionstore.js file present in the user profile folder.
    The box where windows and tabs should be listed is empty.
    I tried to paste a few old sessionstore.js files in the user directory while the firefox.exe process was not active, then opened Firefox again and tried to launch the about:sessionrestore command without any result.
    I think the files are not corrupted because I used most of them in other occasions and I stored them in folders not connected to the common use of any process.
    Also, I already successfully used the about:sessionrestore command in Firefox 29.0.1 in a few other occasions.
    I did a "clean reinstall" of Firefox 29.0.1 and the box contained in the tab where about:sessionrestore is executed is still empty even if the files themselves contain such information as tabs location and html addresses.
    After this I recovered the profile data I had stored in another folder and this is what you can see attached to this question.
    ---------------------------------------------------------------------------------------------------------

    If I select the "show my windows and tabs from last time" option in the startup settings the contents of any savestore.js file i paste in the user profile folder are opened without any problem.
    still, the box in the tab loaded by the about:sessionrestore command is blank and empty, so it's not possible to "de-select" any window or tab. it's necessary to find an editor to modify session backup files which may contain "bad addresses".
    does such an editor already exists?

  • The colors are no longer on my calendar, I have blank boxes where delete and other actions should be, and I can no longer check the little boxes to the left of emails but the star feature does work. How can I fix this?

    The colors denoting my different calendars have disappeared.
    To the right of "MAIL" I have blank boxes.
    When I click on the boxes to the left of in box emails instead of a check mark, there is a straight line on the far left side of the box and the mark disappears as soon as you click on another entry.

    You can control this from Mail Preferences on your computer.  Open Mail, go to Preferences, and select Accounts.
    Go to your MobileMe account and select Mailbox Behaviors.  Next to Trash, select Store Deleted Messages on the Server.

Maybe you are looking for

  • Recent Conversation with MSI and Neo4 overclocking "thing"

    I had a recent email transaction with MSI if anyone is interested. I tried my best to represent the group, and I know we all experience the problem a little bit different which is why it has been hard to explain and fix. I tried to give them the best

  • Can a Column in a Project Plan be set to Read Only for everyone except Admins

    At my company the Project Server Admins create the initial project plans.  We want to add a new column that will designate each task in the plan as Capital or Operational.  We do not want anyone to have the ability to change these. When the Project M

  • Payment and account enquire

    Hi All , I have 3 pending $6.49 payments coming out of my account  - they say they are still 'pending', i would like to cancel them all.  i also have one processed payment of $6.49 that has gone thru my itunes account, and i still cannot see the cred

  • Managing bit flags in an array of bytes

    In my program, I have a large array of bytes. Some arbitrarily long groups of bytes in this array act as groups of bit flags. I need to be able to retrieve and manipulate these bit flags. I read that the best way to do this is with bitwise operations

  • How to use SD_VBAK_ARRAY_READ functional module

    hello can you please tell me how to use SD_VBAK_ARRAY_READ  functional module. that means what i have to pass and what i should get. Please help me