JOptionPane.showConfirmDialog() displays weird msg

I use showConfirmDialog() to request whether or not the program should continue when SUBMIT button is pressed. The first time the button is pressed there are 2 messages displayed in the dialog box: a fake one followed by the real one. This behaviour is not observed if the button is pressed a second time.
This is only noticeable if I connect to the server where it runs using X windows. The same code run on either a LINUX PC or connecting to server using telnet doesn't show this behaviour.
Partial code
public void actionPerformed(ActionEvent ae) {
String msg = new String("Do you really want to submit this list?");
String dtitle = new String("Pls. choose one :)");
int msgType = JOptionPane.QUESTION_MESSAGE;
int optionType = JOptionPane.YES_NO_OPTION;
if (ae.getSource() instanceof JButton && ae.getActionCommand().equals("SUBMIT")) {
jbtn.setBackground(Color.red);
// Confirm dialog
int r = JOptionPane.showConfirmDialog((Component)this,msg,dtitle,optionType,msgType,null);
Thks

Hi m8, thanks got that working......sometimes you just cant see whats stareing you in the face!!
Just one more thing...i have used your code to display the confirmdialog...but is there any way i
can set the default focus to the textfield when the JOptionPane is made?
Thanks again

Similar Messages

  • Tooltip for a JOptionPane.showConfirmDialog??

    I can't get this to work, any ideas on how to reference the OK & Cancel buttons of the "JOptionPane.showConfirmDialog" and create a custom tooltip for each??
    // --------- test to see if the current file was modified and give an option to save first.
    if (changed)
    // ----- display pop-up alert --------------------------------------------------------------
    int confirm = JOptionPane.showConfirmDialog(null,
    "Click OK to discard current changes, \n or Cancel to save before proceeding.", // msg
    "Unsaved Modifications!", // title
    JOptionPane.OK_CANCEL_OPTION, // buttons displayed
                        // JOptionPane.ERROR_MESSAGE
                        // JOptionPane.INFORMATION_MESSAGE
                        // JOptionPane.PLAIN_MESSAGE
                        // JOptionPane.QUESTION_MESSAGE
    JOptionPane.WARNING_MESSAGE,
    null);
    // -- set the tool tip for the buttons here -- ??????
    // public Point getToolTipLocation( MouseEvent event);
    // public JToolTip createToolTip( );
    // toolTipText
    // Point getToolTipLocation( MouseEvent MOUSE_CLICKED);
    JOptionPane.getToolTipLocation(OK_OPTION, Click to discard current changes."")
    // OKButton.setToolTipText("Click to discard current changes.");
    // CancelButton.setToolTipText("Click to save the current file.");
    if (confirm != JOptionPane.YES_OPTION)
    { //user wants to save changes
    try {
    // save the file
    catch(Exception e) {}
    } // close "if (changed)"
    // ----- display pop-up alert --------------------------------------------------------------

    The renderer code has this structure:
    public class MyRenderer extends DefaultTreeCellRenderer {
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean isExpanded, boolean isLeaf, int index, boolean hasFocus) {
              JTextPanel pane = new JTextPanel();
              pane.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
              if (data instanceof MyDataObject) {
                   MyDataObject myObj = (MyDataObject)data;
                   JLabel label = new JLabel();
                   label.setIcon(myObj.getIcon());
                   label.setText(myObj.getInfo());
                   label.setToolTipText("MyTooltip");
                   pane.add(label);
              return pane;
    Thomas Wiedmann

  • JOptionPane.showConfirmDialog

    Hi there,
    I have a confirm dialog that i want to close whenever the [x] is clicked in the top left of the window, but i just keep getting a error.
    I have made a custom confirm dialog that i have added a object to that allows user input.
    I had to do this since I couldnt find out if the OK or Cancel button was pressed on the default one!.
    CODE so FAR....
    Object[] msg = {
    "Please Enter a valid Guess (3-27)", textField};
    result = JOptionPane.showConfirmDialog(null, msg, title,
    JOptionPane.OK_CANCEL_OPTION,
    JOptionPane.PLAIN_MESSAGE);

    Hi m8, thanks got that working......sometimes you just cant see whats stareing you in the face!!
    Just one more thing...i have used your code to display the confirmdialog...but is there any way i
    can set the default focus to the textfield when the JOptionPane is made?
    Thanks again

  • Problem w/JOptionPane showConfirmDialog

    Okay, I have a JOptionPane.showConfirmDialog on a JInternalFrame that works for the most part, but is doing something weird. When a user clicks the Cancel option or closes the JOptionPane, I want it simply to go away. Instead, it will pop up again, and if the user click Cancel or closes the window, it will go away, but it will take the JInternalFrame with it, which I don't want it to do. I have the code pasted below, and it should work the way I have it coded, but it don't. Anyone help??int result = JOptionPane.showConfirmDialog(CustomFrame.this, getTitle() +
       " has been changed. Would you like to save?", "Save File?", JOptionPane.YES_NO_CANCEL_OPTION,
       JOptionPane.WARNING_MESSAGE);
       switch(result)
          default:
             break;
          case JOptionPane.YES_OPTION:
             save();
             break;
          case JOptionPane.NO_OPTION:
             dispose();
             break;
          case JOptionPane.CANCEL_OPTION:
             break;
       }Now this is being triggered from the internalFrameClosing method of the InternalFrameListener interface that is implemented on a private class in my JInternalFrame constructor. And like I said, all other aspects of it work fine and when it's supposed to, but with the Cancel option or closing the JOptionPane (which would trigger the default: option from the switch construct, correct?), I want it to go away. It will pop up a second time, then go away with the JInternalFrame. Any suggestions? Thanks a lot. I'm using JDK 1.4.1 for the Macintosh (15" iMac G4).
    James

    Okay, I have a JOptionPane.showConfirmDialog on a JInternalFrame that works for the most part, but is doing something weird. When a user clicks the Cancel option or closes the JOptionPane, I want it simply to go away. Instead, it will pop up again, and if the user click Cancel or closes the window, it will go away, but it will take the JInternalFrame with it, which I don't want it to do. I have the code pasted below, and it should work the way I have it coded, but it don't. Anyone help??int result = JOptionPane.showConfirmDialog(CustomFrame.this, getTitle() +
       " has been changed. Would you like to save?", "Save File?", JOptionPane.YES_NO_CANCEL_OPTION,
       JOptionPane.WARNING_MESSAGE);
       switch(result)
          default:
             break;
          case JOptionPane.YES_OPTION:
             save();
             break;
          case JOptionPane.NO_OPTION:
             dispose();
             break;
          case JOptionPane.CANCEL_OPTION:
             break;
       }Now this is being triggered from the internalFrameClosing method of the InternalFrameListener interface that is implemented on a private class in my JInternalFrame constructor. And like I said, all other aspects of it work fine and when it's supposed to, but with the Cancel option or closing the JOptionPane (which would trigger the default: option from the switch construct, correct?), I want it to go away. It will pop up a second time, then go away with the JInternalFrame. Any suggestions? Thanks a lot. I'm using JDK 1.4.1 for the Macintosh (15" iMac G4).
    James

  • JOptionPane.showConfirmDialog in Russian

    I have an application that supports many languages including Russian. All other texts are displayed in Russian language correctly. However, I have an issue with JOptionPane.showConfirmDialog() in Russian language. This issue does not occur in ZH or ES. Does anyone know why the JOptionPane.showConfirmDialog() show the Yes/No button in English while the locale is in Russian? How can I fix this issue?
    Thanks!

    Does anyone know why the JOptionPane.showConfirmDialog() show the Yes/No button in English while the locale is in Russian?Tried to track it down, but gave up. So I (still) have no idea.
    How can I fix this issue?Here's one way:import javax.swing.JOptionPane;
    import javax.swing.UIManager;
    public class RussianDialog {
      public static void main(String[] args) {
        UIManager.put("OptionPane.yesButtonText", "Да");
        UIManager.put("OptionPane.noButtonText", "Нет");
        UIManager.put("OptionPane.cancelButtonText", "отменить");
        JOptionPane.showConfirmDialog(null,
                "русский", "русский".toUpperCase(),
                JOptionPane.YES_NO_CANCEL_OPTION);
    }Note that you will need to compile usingjavac -encoding UTF8 RussianDialog.javaif your default encoding doesn't support the Russian characters.
    db

  • Can we add scrollbar to JOptionPane.showConfirmDialog()

    Hi,
    Can we add a scroll bar to JOptionPane.showConfirmDialog() so that the contents(messages) which are to be displayed are present in scrollbar so that the buttons will be visible to the user like OK, CANCEL.
    Currently when the message is large the buttons will not be visble in the screen.
    So, it is possible ? Or there is any other alternative for the same.
    Thanks.

    Is there another library that I have to import? I recieve this error when I try to compile...
    isPrime.java:53: cannot find symbol
    symbol : variable sb
    location: class isPrime
         JTextArea area = new JTextArea(sb.toString() );
    I have javax.swing.* imported as of right now...
         JTextArea area = new JTextArea(sb.toString());
          area.setRows(25);
          area.setColumns(100);
          area.setLineWrap(true);
          JScrollPane pane = new JScrollPane(area);
           JOptionPane.showConfirmDialog(null,
         pane,
           "Test", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    /*         JOptionPane.showMessageDialog(null,
               printArray(array),
         "Thanks for using Reverse Array", JOptionPane.INFORMATION_MESSAGE);
    */       the comment text is what I eventually wish to print((I simply hid it from the compiler so I could play w/ the code you provided)... it is the first 'n' number of primes up to which I'd like to be able to scroll through for large prints over 100 primes.
    thx for the help

  • Positioning JOptionPane showConfirmDialog

    Hi,
    Is it possible to tell the exact position of where a JOptionPane showConfirmDialog is displayed upon execution? Help please!
    Thanks, James

    With a little bit of work, you can do anything in Java!
    In your case, I would suggest using an instance of JOptionPane rather than one of the static methods. The JOptionPane constructors are similar to the static methods in terms of the arguments they take (be careful, though, of mixing up the order of the message and option types). You can then use the createDialog() method to create the JDialog to display the JOptinPane in. Once you have the JDialog, you can use its getLocation() method to find out where it is. Your code might look something liek this:
    import javax.swing.*;
    public class OptionTest extends Object {
    public static void main(String[] args) {
    JOptionPane optionPane =
    new JOptionPane("Hello, World!", JOptionPane.PLAIN_MESSAGE,
    JOptionPane,YES_NO_CANCEL_OPTION);
    JDialog dialog = optionPane.createDialog(null, "Greetings");
    System.out.println(dialog.getLocation());
    dialog.setVisible(true);
    Object value = optionPane.getValue();
    if (value != null && value instanceof Integer &&
    ((Integer)value).intValue == JOptionPane.YES_OPTION) {
    // do something
    Hope this helps.
    Shaun

  • JOptionPane showConfirmDialog title obscured

    Hi there,
    I am using JOptionPane.showConfirmDialog to popup a question to the user, but the title is quite long and is abbreviated in the dialog. Is there any way I can force the popup to size itself so the full title is visible, or at least allow the user to resize it?

    Have you tried creating an instance of a JOptionPane using a constructor and setting its size before calling setVisible?
                        // create an instance of JOptionPane with the selected options
                        JOptionPane window =
                                                      new JOptionPane(message, messageType,
                                                                optionType, null, options, null);
                        // get an instance of the dialog
                        JDialog dialog = window.createDialog(parent, title);
                                    dialog.setSize (500,200);
                        // display the dialog
                        dialog.setVisible(true);

  • JOptionPane.showConfirmDialog: Tabbing between options creates wrong result

    In JOptionPane.showConfirmDialog, when pressing <tab> to move between options and then pressing <Enter> I always get a returned zero (0) no matter which button is in focus. Is this a (known) bug or am I stupid?
    I run the following code.
    import javax.swing.*;
    public class TabOptions
    public static void main (String [] args)
         int n = JOptionPane.showConfirmDialog (null, "Use <Tab> to shift option-button, then press <Enter>. " +
                             "I'll write the returned value to sdt out.");
         System.out.println ("Returned value: " + n);
    }

    import javax.swing.*;
    class TabOptions
    public static void main (String [] args)
    UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);//<--------------------
    int n = JOptionPane.showConfirmDialog (null, "Use <Tab> to shift option-button, then press <Enter>. " +
    "I'll write the returned value to sdt out.");
    System.out.println ("Returned value: " + n);
    }

  • JOptionPane.showConfirmDialog -- remember decision checkbox

    Hi
    JOptionPane.showConfirmDialog -- remember decision checkbox
    is there something to set "remember my decision" for the following dialog box i.e. this dialog sits inside a loop over a set of files
    so if i say "yes overwrite" it should remember that decision. Should i make a dialog box on my own or is there a parameter setting for this
    purpose ?
    if(currentCsvOutputFile.isFile()){
    int userConfirm = JOptionPane.showConfirmDialog(
              new JFrame(),
              currentCsvOutputFile + " already exists , Do you want to overwrite it ? " ,
              "Confirm",
              JOptionPane.YES_NO_OPTION);
    }Regards

    No need for a custom dialog, just add a JLabel and a JCheckBox to a JPanel and pass that as the message parameter.JCheckBox remember = new JCheckBox("Remember my decision");
        JPanel panel = new JPanel(new BorderLayout()); // or whatever layout you find best
        panel.add(new JLabel("File already exists , Do you want to overwrite it ? "), BorderLayout.NORTH);
        anel.add(remember, BorderLayout.SOUTH);
        int userConfirm = JOptionPane.showConfirmDialog(new JFrame(), panel, "Confirm", JOptionPane.YES_NO_OPTION);db

  • JOptionPane.showConfirmDialog  "NO" button acting as "YES" on MAC using TAB

    JOptionPane.showConfirmDialog "NO" button acting as "YES" on MAC using TAB

    Ya , I am asking question ? Why "NO" is acting as "YES" button in case of JOptionPane.showConfirmDialog on MAC using TAB.
    i.e,
    I clicked on some button, then showConfirmDialog is opened, By default the focus is on "YES" button. Now I pressed TAB button and changed to the focus to "NO" button.
    If press ENTER key --> acting "YES"
    If press SPACE key -> acting as "NO"
    Why ?
    What should I do to make it correct ?
    Am I need mention set (Key,value) pairs for UIManager in case of MAC.
    Please suggest ?

  • My PDF bookmarks are displaying weirdly

    My PDF bookmarks are displaying weirdly: they are displaying in blank boxes (apart from the title), rather than as neat single line (or wrapped text) boxes. Also, the left-hand side of the Bookmark column is blank, the bookmark 'thumbnails' are way over to the right ..?? Any idea what's going on?? I'm on a Mac, Acrobat 9

    Hey Salby9,
    Please check with other PDF files how does the bookmarks appear as this might be a document specific issue.
    What version of MAC OS are you using?
    Was this PDF created using Acrobat or other tool?
    Please let me know.
    Regards,
    Anubha

  • Displaying error msg

    hi,
    how i display error msg on page by using af:message from beans, based on some processing? i tried , but error msg is not coming on af:message?
    i m using jdv10g. i checked by system.out.println(errormsg), & it displaying in console, but not on af:message.
    thanks

    hi thanks,
    it is showing the message on af:messages on top of page. i want to display it on af:message fm bean.
    i dragged a af:message fm components palette. i associated its value attribute to errormsg property in bean like this-
    <af:message id="m1" message="#{xxbean.errormsg}"
    inlineStyle="color:rgb(255,0,0);"/>
    //in bean
    private String errormsg = "";
    based on some processing i filled the 'errormsg' property with desirable error string, by this.errormsg="error....." .
    & getter method is there for returing the value, on page.
    GlobalOnly= true for af:messages.
    i m using 10gdev
    Edited by: user78995 on Apr 7, 2010 2:44 AM

  • How to focus No button in JOptionPane.showConfirmDialog?

    How to focus No button in JOptionPane.showConfirmDialog when the Dialog window is opened?
    (default it focus Yes button).
    Please help me. Thank you very much.

    Use the showOptionDialog(...) method then you can specify the buttons and which button has focus.

  • JOptionPane.showConfirmDialog in servlets

    Hi
    I am trying to show a dialog in a doPost method of a servlet. For some reason, it blocks the entire method and does not show the dialog. What gets me voiceless is that it works in the doGet method of the servlet.
    The situation is the following:
    - a first serlvet dispatches GET requests to other servlets according to the role of users.
    - in the doGet of this first servlet, a second (servlet2) is instantiated and its doGet is called;
    - in the doGet of servlet2, a HTML form (POST method) is generated;
    - when the submit button of the HTML form is pressed, the form is processed by the doPost of servlet2.
    JOptionPane.showConfirmDialog works in servlet2 only in the doGet and not in the doPost. Their code is:
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    DataModule1 dm = (DataModule1) ixPageProducer1.getSessionDataModule(request.getSession());
    dm.parameterRow1.setString("empl_ini", request.getRemoteUser());
    dm.queryDataSet1.refresh();
    empl_id = dm.queryDataSet1.getInt("number");
    ixPageProducer1.servletGet(this, request, response);
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    DataModule1 dm = (DataModule1) ixPageProducer1.getSessionDataModule(request.getSession());
    dm.queryDataSetReq.insertRow(false);
    ixPageProducer1.servletPost(this, request, response);
    JOptionPane.showConfirmDialog(null, "test" , "Request Confirmation", JOptionPane.YES_NO_OPTION);
    (I am using JBuilder and its InternetBeans to link the HTML pages with the DB).
    Many thanks in advance for helping a desperate Java beginner!!!

    I figured out that the dialog was actually generated, but "behind" my browser.You can try this to add the following either before or after the JOptionPane.showConfirmDialog:
    JOptionPane.requestFocus();
    But I think your best bet is to associate a frame with your dialog box as follows:
    Object parent = this.getParent();
    while (!(parent instanceof Frame)) parent = ((Component)parent).getParent();
    F = (Frame)parent;
    JOptionPane.showConfirmDialog(F, "test" , "Request Confirmation", JOptionPane.YES_NO_OPTION);
    If this helps, don't forget the Dukes
    ;o)
    V.V.

Maybe you are looking for