Mnemonic in JOptionPane dialogs

In the dialogs opening with JOptionPane.showConfirmDialog(...) There are mnemonics 'Y' & 'N' set for Yes & No options resp.
Yes option can be chosen with Alt+Y & No option with Alt+N
Is there any WorkAround that by just pressing 'Y' option Yes is selected. (like there with option dialogs in windows).

Here you go ... I have written the code for you ..
package ramanujam.test;
import javax.swing.*;
import java.awt.event.*;
public class TestKeyOnPane extends JOptionPane implements ActionListener, KeyListener
      * Create Constants for users to get notified of the button clicked
          public static final int YES_BUTTON_PRESSED = 0;
          public static final int NO_BUTTON_PRESSED = 1;
          public static final int CANCEL_BUTTON_PRESSED = 2;
          public static final int OK_BUTTON_PRESSED = 3;
          public static final int CUSTOM_BASE_VALUE = 4;
          private int selectedButtonValue = -1;
          StringBuffer usedMnemonics = null;
          private JButton[] bOptionsX;
      *Inner Action Listener to take care of Property Change Notification
     class PropertyActionListener implements ActionListener
          public void actionPerformed(ActionEvent ae)     {
               setValue(ae.getSource());
*private KeyListener to setValue on enter key to the respective value and
* -1 on exit.
class PropertyKeyListener extends KeyAdapter
     private JButton[] bInnerObj;
     public PropertyKeyListener(JButton[] bInnerObjParam)
          bInnerObj = bInnerObjParam;
     public void keyPressed(KeyEvent ke)
          int code = ke.getKeyCode();
          /*               if(code == KeyEvent.VK_ENTER)
                              for(int i=0;i<bInnerObj.length;i++)
                                   if(bInnerObj.hasFocus())
                                        bInnerObj[i].doClick();
                                        break;
          for (int i = 0; i < bInnerObj.length; i++)
               char cc[] = {(char) code};
               String str = new String(cc);
               if (bInnerObj[i].getText().startsWith(str))
                    bInnerObj[i].doClick();
                    break;
     * Constructor - to match that of parent class
     * Creates a MojoActionOptionPane with a test message.
     public TestKeyOnPane()
          this("MojoActionOptionPane Message",PLAIN_MESSAGE,OK_OPTION,null,new Object[]{"OK"},null);
     *Creates a instance of MojoActionOptionPane to display a message using the plain-message  message type
     *and the default options delivered by the UI.
     *@param message - The message to be displayed
     public TestKeyOnPane(Object message)
          this(message,PLAIN_MESSAGE,OK_OPTION,null,new Object[]{"OK"},null);
     *Creates an instance of MojoActionOptionPane to display a message with the specified message
     *type and the default options,
     *@param message The message to be displayed
     *@param messageType The Type of message to be displayed
     public TestKeyOnPane(Object message, int messageType)
          this(message,messageType,OK_OPTION,null,new Object[]{"OK"},null);
     *Creates an instance of MojoActionOptionPane to display a message with the specified message type
     *and options.
     *@param message The message to be displayed
     *@param messageType The Type of message to be displayed      
     *@param optionType The Type of User Action Options to be displayed
     public TestKeyOnPane(Object message, int messageType, int optionType)
          this(message,messageType,optionType,null,new Object[]{"OK"},null);
     *Creates an instance of MojoActionOptionPane to display a message with the specified message type,
     *options, and icon. 
     *@param message The message to be displayed
     *@param messageType The Type of message to be displayed
*@param optionType The Type of User Action Options to be displayed
     *@param icon The Icon to be displayed on the option pane
     public TestKeyOnPane(Object message, int messageType, int optionType, Icon icon)
this( message, messageType, optionType, icon,new Object[]{"OK"},null);
     *Creates an instance of MojoActionOptionPane to display a message with the specified message type,
     *icon, and options.
     *@param message The message to be displayed
     *@param messageType The Type of message to be displayed
*@param optionType The Type of User Action Options to be displayed
     *@param icon The Icon to be displayed on the option pane
     *@param options     A Collection of values from which the user can select     
     public TestKeyOnPane(Object message, int messageType, int optionType, Icon icon, Object[] options)
this(message, messageType, optionType, icon, options,options[0]);
     *Creates an instance of MojoActionOptionPane to display a message with the specified message type,
     *icon, and options, with the initially-selected option specified. 
     *@param message The message to be displayed
     *@param messageType The Type of message to be displayed
*@param optionType The Type of User Action Options to be displayed
     *@param icon The Icon to be displayed on the option pane
     *@param options     A Collection of values from which the user can select
     *@param initialValue The Default Selected Value for the OptionPane
     public TestKeyOnPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue)
super(message, messageType,optionType,icon,options,initialValue);
          setOptions(options);
setInitialValue(initialValue);
     * Event Handler to take care of enter,escape or any other case
     * Here, we check the button clicked, we set the clicked buttons
     * index using the caption of the button.
     * @see setSelectedButtonValue()
     * method.
          public void actionPerformed(ActionEvent ae)
               String actionCommand = ae.getActionCommand();
               if(actionCommand.equalsIgnoreCase("OK"))
                    setSelectedButtonValue(OK_BUTTON_PRESSED);
               else if(actionCommand.equalsIgnoreCase("CANCEL"))
                    setSelectedButtonValue(CANCEL_BUTTON_PRESSED);
               else if(actionCommand.equalsIgnoreCase("YES"))
                    setSelectedButtonValue(YES_BUTTON_PRESSED);
               else if(actionCommand.equalsIgnoreCase("NO"))
                    setSelectedButtonValue(NO_BUTTON_PRESSED);
               else
                    int temp = CUSTOM_BASE_VALUE+findIndexOfCustomButton(actionCommand);
                    setSelectedButtonValue(temp);
     protected int findIndexOfCustomButton(String title)
          for(int i=0;i<options.length; i++)
               String strTitle = ((JButton)options[i]).getText();
               if(strTitle.equalsIgnoreCase(title))
                    return i;
          return -1;
     * Read only method that returns an int corresponding to the value of the button
     * clicked by the user
     * @return int The index of the selected button.
     * @see setSelectedButtonValue()
     * If the default YES, NO , CANCEL or OK buttons are used with the OptionPane,
     * the indices for the same defined by the constants in this class are used.
     * the indices 0 to 3 are reserved for the default buttons.
     * To get the indices for the custom buttons, the return value is decided by
     * its index in the options array + a base value 4, that is used to avoid
     * any possible ambiguity with the default button index.
     public int getSelectedButtonValue()
          return this.selectedButtonValue;
* Invoked when a key has been pressed.
public void keyPressed(java.awt.event.KeyEvent ke)
          int code = ke.getKeyCode();
          /*               if(code == KeyEvent.VK_ENTER)
                              for(int i=0;i<bInnerObj.length;i++)
                                   if(bInnerObj[i].hasFocus())
                                        bInnerObj[i].doClick();
                                        break;
          for (int i = 0; i < this.options.length; i++)
               char cc[] = {(char) code};
               String str = new String(cc);
               if (bOptionsX[i].getMnemonic() == code || ((char)bOptionsX[i].getMnemonic()) == Character.toUpperCase(cc[0]))
                    bOptionsX[i].doClick();
                    break;
     * Invoked when a key has been released.
public void keyReleased(java.awt.event.KeyEvent e) {}
     * Invoked when a key has been typed.
     * This event occurs when a key press is followed by a key release.
public void keyTyped(java.awt.event.KeyEvent e) {}
     *This method sets the Mnemonics for the buttons
     *@param buttons - Array of JButtons for which mnemonics are to be set
     *@return void
     protected void setMnemonics(JButton[] buttons)
          * 1. Get the button array
          * 2. Check if they are the default buttons.
          * 3. If they are, then set the first character as the mnemonic, since Yes, No, Cancel
          * and OK do not have common first characters.
          * 4. Else, if the buttons are custom defined, then get the first non ambiguous
          * character from the button's text and set that as the mnemonic          
          usedMnemonics = new StringBuffer();     
          int buttonsLen = buttons.length;
          String strArr[] = new String[buttonsLen];
          defaultMnemonicSetter:for(int i=0;i<buttonsLen;i++)
               strArr[i] = buttons[i].getText();
               if(strArr[i].equalsIgnoreCase("OK") || strArr[i].equalsIgnoreCase("Cancel") || strArr[i].equalsIgnoreCase("Yes") || strArr[i].equalsIgnoreCase("No"))
                    buttons[i].setMnemonic(strArr[i].charAt(0));
                    usedMnemonics.append(strArr[i].charAt(0));
               else
                    char charAt0[] = {strArr[i].charAt(0)};
                    String strAt0 = new String(charAt0);
                    customMnemonicSetter :for(int j=0;j<strArr[i].length();j++)
                         char charAt0j[] = {strArr[i].charAt(j)};
                         String strAt0j = new String(charAt0j);
                         if(usedMnemonics.toString().indexOf(strAt0j) == -1)
                              buttons[i].setMnemonic(charAt0j[0]);
                              usedMnemonics.append(charAt0j);
                              break customMnemonicSetter;                     
                         else
                              continue customMnemonicSetter;
     *method that takes care of Adding actionListeners to
     *the buttons that are created by the OpionPane based on options
     *specified by the user
     *@param options[] - Array of type Object that holds the Button Options
     public void setOptions(Object options[])
          int len = options.length;
          Object optionsCopy[] = new Object[len];
          JButton buttonsCopy[] = new JButton[len];
          bOptionsX = new JButton[len];
          for(int i = 0; i < len; i++)
               String optionTitle = options[i].toString();
               JButton bBuff = new JButton(optionTitle);
               bBuff.addActionListener(this);
               bBuff.addActionListener(new PropertyActionListener());
               optionsCopy[i] = bBuff;     
               buttonsCopy[i] = bBuff;
               bOptionsX[i] = bBuff;
               //bBuff.addKeyListener(new PropertyKeyListener(buttonsCopy));
               bBuff.addKeyListener(this);
          setMnemonics(buttonsCopy);
          buttonsCopy = null;
          super.setOptions(optionsCopy);
          optionsCopy = null;
     * private mutator to set the value of the selected button
     * @param value - the value to be set
     * @see getSelectedButtonValue()
     private void setSelectedButtonValue(int value)
          this.selectedButtonValue = value;

Similar Messages

  • Customized KeyboardFocusManager problems with JOptionPane-Dialogs

    Hi,
    I have a problem I'm not able to solve: With Java 1.4.2 unter Linux, as well as all newer Java Versions (1.4, 1.5, 1.6) under Windows, dialogs created by JOptionPane.showXXXDialog do not react to keyboard events like <Tab> any more when using a customized KeyboardFocusManager. Java 1.5 and 1.6 under Linux work fine.
    Here is what I did:
    I have a JFrame and want some customized focus control when navigating through the Frame with <Tab>. Therefore I've implemented a class
    public class EfaFrameFocusManager extends DefaultKeyboardFocusManagereand said in the main JFrame:
    EfaFrameFocusManager myFocusManager = new EfaFrameFocusManager(this,FocusManager.getCurrentKeyboardFocusManager());
    FocusManager.setCurrentKeyboardFocusManager(myFocusManager);The constructor of my EfaFrameFocusManager stores the JFrame (this) and the original KeyboardFocusManager (2nd arg) for later use. Within my own FocusManager, I've implemented the method
    public void processKeyEvent(Component cur, KeyEvent e)which is checking whether the desired Frame (efaFrame) is currently active or not. If it is active, it's performing my customized operations which is working well. If it is not active (e.g. because a dialog created with JOptionPane.showConfirmDialog() is open), it should perform default actions. So I said within processKeyEvent:
    if (!efaFrame.isActive()) { // efaFrame is the previous "this" arg
      fm.processKeyEvent(cur,e); // fm is the previously stored CurrentKeyboardFocusManager
      return;
    }Instead of invoking processKeyEvent on the original KeyboardFocusManager fm, I also tried super.processKeyEvent(cur,e);, but without any change in behavior.
    As I said before, this is working well under Java 1.5 and 1.6 with Linux.
    However, it is not working unter Windows (any Java version I tried, including 1.4, 1.5 and 1.6) and also not unter Linux with Java 1.4. With these combinations, dialogs created by JOptionPane.showXXXDialog(...) do not respond to the <Tab> key. I do see that my own FocusManagers processKeyEvent method is invoked, and I also see that it invokes the one of the original FocusManager, but the Dialog doesn't react.
    What am I doing wrong?
    Nick.

    I have a JFrame and want some customized focus control when navigating
    through the Frame with <Tab>. sounds like you should be doing this via a FocusTraversalPolicy
    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#customFocusTraversal

  • Growing a JOptionPane dialog vertically

    I am writing a simple JPanel for use within message dialogs.
    Just wanted to add "more details" functionality really, for error dumps etc.
    I've so far used this with JOptionPane:
         DetailsPanel detailsPanel = new DetailsPanel();
         detailsPanel.setMessage("Some error occurred");
         detailsPanel.setMessageDetails("Error dump details, stack trace, blah blah...");
         JOptionPane.showMessageDialog(frame, detailsPanel, "ERROR", JOptionPane.ERROR_MESSAGE);
    However, when the button is clicked to display the extra details, the dialog doesn't resize to account for the extra text. I'm using a GridBagLayout manager, but previously had a BorderLayout. Neither seem to work. Have tried adding to a frame manually, same effect. Tried explicitly resizing the panel and parent, revaliding, invalidating, repainting blah blah.
    Am I missing something obvious? Thanks for any help. Andy.
    Here is the class:
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    * Displays a string message and allows user to expand "more details" for
    * error output etc.
    * Can be used in conjunction with javax.swing.JOptionPane:
    *           DetailsPanel details = new DetailsPanel();
    *           details.setMessage("Something bad happened");
    *           details.setMessageDetails("Error code 12345 -- system dump, stack trace...");
    *           JOptionPane.showMessageDialog(someParentComponent, details, "ERROR", JOptionPane.ERROR_MESSAGE);
    * @version 1.00 21/05/02
    * @author Andy Carter ([email protected])
    public class DetailsPanel extends JPanel implements ActionListener
         private static final String MORE_DETAILS = "Details >>";
         private static final String LESS_DETAILS = "<< Details";
         private boolean detailsHidden = true; // default
         private JLabel messageLabel; // used to display a message
         private JButton detailsButton; // used to control whether or not "more details" are visible
         private JTextArea detailsTextArea; // used to display "more details" about the message
         private JScrollPane detailsScrollPane; // used to allow scrolling over the text-area
         private JPanel internalPanel; // used for a better layout
         * Default constructor.
         * Sets up...
         public DetailsPanel()
              super();
              /* Set up the controls: */
              messageLabel = new JLabel();
              detailsButton = new JButton(MORE_DETAILS); // because detailsHidden == true
              detailsButton.addActionListener(this);
              detailsTextArea = new JTextArea();
              detailsTextArea.setEditable(false); // user can copy to clipboard but not edit the text
              detailsScrollPane = new JScrollPane();
              detailsScrollPane.setViewportView(detailsTextArea);
              detailsScrollPane.setVisible(false);
              /* Set the layout for and add all the components: */
              setLayout(new GridBagLayout());
              GridBagConstraints constraints = new GridBagConstraints();
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridx = 0;
              constraints.gridy = 0;
              add(messageLabel, constraints);
              constraints.gridy = 1;
              add(detailsButton, constraints);
              constraints.gridy = 2;
              add(detailsScrollPane, constraints);
         * Sets the message to be displayed.
         * @param message java.lang.String
         public void setMessage(String message)
              messageLabel.setText(message);
         * Gets the message to be displayed.
         * @return java.lang.String
         public String getMessage()
              return messageLabel.getText();
         * Sets the extra details about the message.
         * displayed by
         * @param message java.lang.String
         public void setMessageDetails(String message)
              detailsTextArea.setText(message);
         * Gets the extra details about the message.
         * @return java.lang.String
         public String getMessageDetails()
              return detailsTextArea.getText();
         * Fired when the an action is performed on the "more details" button.
         * Makes any extra details about the message visible.
         public void actionPerformed(ActionEvent e)
              /* Toggle whether or not details are hidden: */
              detailsHidden = !detailsHidden;
              detailsScrollPane.setVisible(!detailsHidden);
              /* Set the text of the button to indicate the current state: */          
              String newButtonText = detailsHidden ? MORE_DETAILS : LESS_DETAILS;
              detailsButton.setText(newButtonText);

    Pass in the java.awt.Window reference in the DetailsPanel constructor. Then, when the user clicks the "Details" button, call window.pack( ). This will make the frame/dialog resize.
    From your code:
    private Window window ;
    public DetailsPanel(JFrame window)
    super();
    this.window = window ;
    String newButtonText = detailsHidden ? MORE_DETAILS : LESS_DETAILS;
    detailsButton.setText(newButtonText);
    window.pack( ) ;
    }

  • How to get handle to JOptionPane dialog

    Hi,
    I'm working on a gui application which can generate dialogs when errors occur.
    The problem I have, is the following :
    Somewhere in the process, we show an info message this way :
    JOptionPane.showMessageDialog((Component)parent, "This request may take up to 30 seconds...");Later on, another thread can generate an error message to inform the user that there was an error while processing the request. In this case, the first info dialog should be removed automatically (in case the user didn't close it yet).
    From the thread, I have access to the parent object which is a JInternalFrame object.
    Is there any way I can access the info dialog from the JInternalFrame object?
    Thanks very much for your help!

    check out [url http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ProgressMonitor.html]javax.swing.ProgressMonitor which I think would fit your needs better than JOptionPane.
    However, if you still want to use JOptionPane, check out it's [url http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JOptionPane.html]API spec, which includes how to access the JDialog directly (see the bottom of the class description).

  • More and more JOptionPane dialogs

    weirdest problem I've ever had.. so far..
    applet works fine in applet viewer.. and in browser
    thing is.. I have a button to save to database.. works fine.. when saved I used a JOptionPane to show a message with something like "save completed" all works..
    problem starts when you leave the page.. go to another page.. there the applet gets loaded with diffrent parameters.. and then save that one.. now you'll get 2 JOptionPanes.. with the same message..
    go to some other page and save again and you'll get 3.. etc..
    JOptionPane.showMessageDialog(null, "De flowchart is opgeslagen!", "Opgeslagen", JOptionPane.INFORMATION_MESSAGE);that's the optionpane.. gets called when the loop for saving to database is done..
    **EDIT**
    hmm.. this is interesting.. same problem 3 years ago
    http://forum.java.sun.com/thread.jspa?forumID=421&threadID=514751
    Edited by: Nizzle on Nov 27, 2007 2:21 PM

    Hi SLaGFYmanny
    Could you please start a new thread for your question instead of posting in an existing thread?
    Then you can provide more information like your operating system and installed extensions and installed plugins.
    *[[/questions/new start a new thread]]
    *[[/kb/Using+the+Troubleshooting+Information+page]]
    You can try basic steps like these in case of issues with web pages:
    Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Hold down the Shift key and left-click the Reload button
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (Mac)
    Clear the cache and cookies only from websites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Do you think JOptionPane dialogs force garbage collection afterwards?

    I ask because I've made a nested static class to implement my own file selection tool; the problem is that each time I call it the old JPanel is being recalled and so the components get re-added to it each time it's called, resulting in n versions of each file for every n times you open it.
    I'm running myDialog.dispose() upon exiting, so is my only option now manual garbage collection? How could I force it to be garbage collected? Because System.gc() seems to have no effect.

    Strictly speaking there is no way to force garbage collection, so, no, JOptionPane will not be doing it.
    You almost certainly have a leak in your code. Post it and we may be able to help.

  • JOptionPane dialog - always toFront

    Is there any way to insure that a dialog issued from an application will
    always come to front when executed from within an app?
    I tried using the toFront() method of frame with mixed results...
    If nothing is happening on desktop it seems to work but if I'm doing something
    else it doesn't. I need this dialog to grab attention when executed
    thanks for any help - JP

    If you want the dialog to "stop" the application untill the user interacts in any way with the dialog and press some kind of "Acept" or "Cancel" button mke it modal:
    new JDilog(frame_parent, true)
    this line makes a modal (it's modal because of the second argument) dialog wich will be allways on top of the Frame frame_parent until it's disposed.
    Hope it helps.
    Abraham

  • Custom Dialogs - JOptionPane

    Hi Guys,
    I was after a quick bit of advice. I've written a small routine which handles the JOptionPane dialog when a user wants to delete some files/folders from within my app. I originally had a "showConfirmDialog" type dialog, but I also needed a "Yes to All" button too (for multiple selections). In essence its a YES_NO_CANCEL_OPTION - with an added "Yes to All" choice. I couldn't find a YES_YESTOALL_NO_CANCEL option in the "optionType" parameter in the Docs.
    Heres what I've got...
    protected int deleteFileCheck(File theFile) {
    String fileOrFolder;
    fileOrFolder = theFile.isDirectory() ? "folder" : "file";
    Object[] options = {"Yes", "Yes to All", "No", "Cancel"};
    return JOptionPane.showOptionDialog(null,theFile.toString()
    + "\n" + "Are you sure you want to delete this "
    + fileOrFolder + "?",
    "Delete files from this project",
    JOptionPane.DEFAULT_OPTION,
    JOptionPane.WARNING_MESSAGE,
    null, options, options[0]);
    which returns -1 for "close", 0 for "yes", 1 for "yes to all", 3 for "no" and 4 for "cancel". This seems to work okay.
    Is this the best way to do this??
    I'm just double checking really...
    Many thanks in advance.

    Thanks for replying. I'll try to address your questions.
    - Why restrict the design to having only one instance
    of the frame? What purpose or requirement does that
    fulfill?The app has a single JFrame that serves as the main window for the application. It implements an MDI desktop. Since the app is capable of handling multiple documents, there's no need for other instances of the main JFrame.
    You're still free to invoke another instance of the app, but that will be in its own JVM with its own singleton.
    - I think you pointed out your problem without
    realizing it - why is the frame being passed around
    to a bunch of methods? Who controls the frame? The app has many classes that subclass JDialog. JDialog's constructor expects a reference to the Frame or Dialog that owns it. I could use null here, but it's a personal preference to include it if possible.
    The frame controls itself. For example, when the user takes some action that requires adding a new JInternalFrame, the code calls MyMainClass.getMDIDesktop().addInternalFrame() (assuming getMDIDesktop() is left as a static method; if not, the call becomes MyMainClass.getInstance().getMDIDesktop().addInternalFrame()).
    - Should the controller of the frame provide
    it on demand (accessor) instead of handing it off to
    everyone to use for their own purposes? I guess I don't understand how what you're suggesting is substantially different than what I'm proposing. The (singleton) controller of the frame (which happens to be the frame itself) provides a reference (via .getInstance()) to whoever needs it -- rather than passing it explicitly.
    - Who's creating all these dialogs such that they
    need their own reference to the frame - why isn't it
    the same class that controls the frame?The reference is often just to establish parentage, but also to allow various dialogs access to methods to create new internal frames/update existing internal frames/etc.

  • JOptionPane localiztion

    JOptionPane localization
    Hi
    How can localize JOptionPane Dialog to fit some local
    I am using Arabic in my application and and I use Arabic locale but
    JOptionpane is still in English
    instead of yes no cancel I want another words appera
    thanks

    Hi,
    I don't know for sure. But I would investigate to modify/add the localization files of your JDK. I know that this is possible although I have never done that.
    Please let me know if you succed!
    Good luck!
    null

  • Focus Problem -- Two Non Modal Dialogs

    Hi ,
    In my applet, when user does something which is not allowed, I display an error message box (JOptionPane dialog - modal).
    There is another dialog box (non modal) that user
    can open to view search results and put it aside the
    applet window to do some parallel work.
    Now when error message dialog appears, the search
    dialog box also pops up even if the user
    has put this behind the applet window (by clicking browser window or applet, the search dialog goes behind the window).
    Can you please let me know, how can I get rid
    of this search dialog (non-modal) popup. I mean
    search dialog should remain open but should not
    come infront (ie should not get focus) when modal
    error message dialog pops up.
    NOTE: I don't want to make search dialog
    a modal dialog.
    Thanx,
    [email protected]

    Thanks for the reply michael. I forgot to mention particularly during my post that i am facing this problem on Solaris system. Running the same application on windows is working fine. I can't make other non-modal dialogs visibility to false because they should be visible on the screen all the time throught out the application life cycle and making it visible/non-visible doesn't get sense in my application. Does anybody is facing the same problem with Solaris system? Plz help.
    Hitesh

  • Changing background in a JOptionPane

    This is probably very simple, but I'm having some trouble. I simply want to change the background of the message in my JOptionPane dialog box (and also change the font of the message, but I think I figured that one out). Here's the code....
    JLabel label1 = new JLabel("the first part of message");
    JLabel label2 = new JLabel("the second part of the message");
    label1.setFont(Utils.courierBold12);
    label2.setFont(Utils.courierBold12);
    JPanel panel = new JPanel();
    panel.setBackground(Color.white);
    panel.setLayout(new BorderLayout());
    panel.add(label1, BorderLayout.NORTH);
    panel.add(label2, BorderLayout.CENTER);
    JOptionPane pane = new JOptionPane(panel,JOptionPane.WARNING_MESSAGE);
    pane.setBackground(Color.white);
    // pane.setOpaque(true);
    JDialog dialog = pane.createDialog(this, "Error Message");
    dialog.setBackground(Color.white);
    dialog.show();
    first I tried to set the pane.setOpaque(false) but that left only the panel background white (the rest is that boring gray color). When I set the pane.setOpaque(true) the panel background is white as well as the top and bottom of the dialog box, but not the Icon or the container the has the ok button in it. How can I set the entire dialog box background to white??? Thanks for any and all help....

    Please provide more information about what you are trying to do.

  • I18n for JOptionPane

    I have a JOptionPane with OK/Cancel options.
    I change the Default Locale when i need to change the app language.
    It's alright when I change the default Locale the first time..the Ok and Cancel are shown in the appropriate language...(in the JOptionPane)
    but when i'm changing the Locale the second time say back to English....it doesn't work....
    I have done no Locale changes in the JOptionPane code....
    using current;y JDK 1.4.1_02
    Win/Mac
    Any suggestions...!

    I have observed that when launching an application from the command line using the -Duser.region= and -Duser.language= arguments, that any JOptionPane dialogs one's application might show shall always display their text using that language and locale no matter whether your program should call Locale.setDefault(), System.setProperty(), UIManager.setLookAndFeel(UIManager.getLookAndFeel()), or anything else you may try, at runtime. On the other hand, I have observed that if you launch your application WITHOUT having set those properties on the command line, then Locale.setDefault() and UIManager.setLookAndFeel(UIManager.getLookAndFeel()) will successfully cause JOptionPane to display all of its text using the "current" locale. This is true for the Windows, Motif and Metal look and feels on both Mac and Windows, under JDK 1.4 and 1.5. On Mac OS X however, the "Mac OS X" look and feel will "switch" (pun intended) to the current locale irrespective of whether or not the user.language and user.region system properties were set on the command line at launch time. This, I assume, is an instance of Macintosh "doing the right thing" for the end user despite what Java's designers may have had in mind...
    To be frank, I would appreciate an authoritative answer from someone at Sun on this issue, as to whether or not the behavior I have described is intended -- and if so, why -- or whether it is a bug, or whether I have overlooked some salient fact in the Java documentation that I have no excuse for having overlooked.
    Thank you for your time,
    JL

  • InputVerifier and JOptionPane help please

    I am trying to create an application and require to validate input fields. I have successfully written the code to use the InputVerifier class to validate the input but want to use a JOptionPane dialog to notify errors. This doesn't seem to work as the JOption Pane is treated as an attempt to shift focus from the field being validated (which calls shouldYieldFocus() which tries to show a JOptionPane which tries to shift focus .........). I have a temporary fix by using an disabled text field to display the message but it isn't very elegant. Anyone any ideas please ?

    Did you get any solution?
    I am also facing the same problem but with Jdk 1.4 only.
    In Jdk 1.3 it's working fine.
    Please let me know if u have any solution

  • Problem in showMessageDialog method of JOptionPane

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SwingComp extends JFrame implements ActionListener{
    public SwingComp()
    JPanel p = new JPanel();
    JButton b = new JButton("OK");
              b.addActionListener(this);
    p.add(b);
                    add(p);  
                    pack();
                    setVisible(true);
    public static void main(String args[])
              new SwingComp();
    public void actionPerformed(ActionEvent e)
              JOptionPane.showMessageDialog( null, "Message", "Title", JOptionPane.ERROR_MESSAGE );
    //JDialog d = new JDialog();
    //JButton b1 = new JButton("some");
    //d.add(b1);
    //d.pack();
    //d.setVisible(true);
    }After running the above code is there any way in which I can add action listener to the ok button that is displayed by JOptionPane.showMessageDialog( null, "Message", "Title", JOptionPane.ERROR_MESSAGE ); dialog.

    You'll need to customize the option pane in order to
    achieve what you want. The following link
    demonstrates customizing a JOptionPane dialog.
    You'll need to adapt the code for your purposes but
    it clearly demonstrates the technique.
    http://forum.java.sun.com/thread.jspa?forumID=513&thre
    adID=248471Thanks for the information. Is there any other way by which the problem can be solved, I mean without customising...

  • Help Button in JOptionPane

    Hi all,
    is there any easy way to provide a (possible locale sensitive) Help Button in JOptionPane Dialogs? Are there any libs that extend the Standard Dialogs to provide such a button?
    Many thanks for your ideas!
    bye
    Marcus

    This guy made his own alternative OptionPane that has such a feature:
    [http://javagraphics.blogspot.com/2008/06/joptionpane-making-alternative.html|http://javagraphics.blogspot.com/2008/06/joptionpane-making-alternative.html]

Maybe you are looking for

  • How do I update my iMAC with Intel chips beyond 10.4.11 ?

    From the days of the Apple 1 until the days of the first Mac I was an Apple user. Then corporate America drug me away kicking and screaming to the Windows world. Now I have bought a used iMac with Intel chips to use as an Apple Forensics test machine

  • Unknown error occured (13005)

    itunes was installed and then stopped working, have uninstalled numerous times and re installed, but always get the same error message. I have done everthing I can but nothing helps. Can anyone help? Thanks

  • SAP Process Email with pdf attachments

    Folks, Background: Scheduled processes that run daily sends out emails to our users within SAP. It's also converts the spool to a .pdf file and attaches it in the email. Users can view this pdf (this is essentially a report). It's been working great!

  • Function module (Incound idoc)

    Hi please advise when creating an Inbound FM from scratch the are some exporting parameter such as *"             VALUE(WORKFLOW_RESULT) LIKE  BDWFAP_PAR-RESULT *"             VALUE(APPLICATION_VARIABLE) LIKE  BDWFAP_PAR-APPL_VAR *"             VALUE

  • Why is my firefox a transparent blank window every time i open it

    Everytime i open my firefox its a blank blue transparent screen , please help ive restarted my machine and everything and if i deleate it and reinstall will i loose all my bookmarks ? thanks Vimo