Key-enable buttons on a JOptionPane

Hi,
The existing code in my Application uses a JOptionPane static method = JOptionPane.showOptionDialog() to create a dialog box.Is there any way I can key-enable the buttons on the dialog created by this method.
public int createAndShowGUI() {
if (!issuesPanel.hasIssues())
return -2; //TODO make constant
else {
//Custom button text
String[] options = should_continue ? new String[] {returnText, continueText} : new String[] {returnText};
int optionButtons = should_continue ? JOptionPane.OK_CANCEL_OPTION : JOptionPane.CANCEL_OPTION ;
log.info("IssuesOptionPane displayed - " + title);
int optionChosen = JOptionPane.showOptionDialog(parent,
issuesPanel.createAndGetIssuesPanel(),
title,
optionButtons,
JOptionPane.PLAIN_MESSAGE,
null, //don't use a custom icon
options, //titles of buttons
null); //no default selected button
String buttontext = optionChosen == CLOSE ? "X" : options[optionChosen];
log.info("User clicked on the " + buttontext + " button");
return optionChosen;
I see that there is no way to get a handle on the JButtons created by the JOptionPane.So, one work around that I tried is to create a JPanel, add JButtons , set Input Map, set Action Map ( to add key bindings ) on it.Then create a JDialog and pass this JPanel to the dialog using setContentPane
     private static void createAndShowGUI(){
          JButton bookingButton=new JButton(bookStr);
          JButton returnButton=new JButton(returnStr);
          bookingButton.addActionListener(new BookAction());
          returnButton.addActionListener(new ReturnAction());
          JPanel panel=new JPanel();
          panel.add(bookingButton);
          panel.add(returnButton);
          panel.setActionMap(initActionMap());
          initAndSetInputMap(panel);
          JDialog dialog=new JDialog();
          dialog.setSize(400,100);
          dialog.setModal(true);
          dialog.setContentPane(panel);
          dialog.addPropertyChangeListener(indicator,listener);
          System.out.println("step 1" );
          dialog.pack();
          System.out.println("step 2");
          dialog.setVisible(true);
But the problem that I am facing here is that the property change events triggered by the code inside the actionPerformed methods is not getting capturesd by the listener attached to the JDialog.
Any thoughts?
Thanks
Aman

google: JOptionPane mnemonics
http://www.devx.com/tips/Tip/13718
http://forum.java.sun.com/thread.jspa?threadID=321824&messageID=1649963
http://coding.derkeiler.com/Archive/Java/comp.lang.java.gui/2005-03/0495.html
etc.

Similar Messages

  • Prevent games from grabbing every key & mouse button

    I've been gaming a lot of native linux games (especially the Humble Bundle ones), and a great deal of them tend to grab the all the keyboard and mouse keys/buttons.
    This means that NO keys work; for example, I've a mouse with lots of buttons, and some of these control my volume (via xbindkeys). Some media keys on my keyboard do this as well, and control vlc play/stop (also via xbindkeys), and some other switch desktop, minimize, etc (via compiz keybinds).
    Is there a way to keep these games for grabbing these keys/mouse-buttons? I kind of lose control of my desktop while they're running. I belive they grab the mouse entirely somehow, though I must admit, I'm not an expert on this area.

    I've made two AUR packages for this:
    https://aur.archlinux.org/packages.php? … _Search=Go
    I'm just using libx11-nokeyboardgrab now, so I let the sdl one go unmaintained.
    libx11-nokeyboardgrab is incompatible with dmenu (edit: and password screensavers), but works with everything (also dialog pop-ups).
    sdl-nokeyboardgrab doesn't grab non-sdl programs (Virtualbox, maybe Wine, I haven't tested it).
    It doesn't prevent mouse grab, because that's necessary for FPS games and Virtualbox mouse mode.
    I have thought of adding in a mechanism where the mouse is only grabbed on some condition. Like the existence of a "/tmp/grabmouse" file. But I've been fine without it.
    One problem that occurs even with mouse grab enabled is that when the game loses focus, it loses the mouse grab too. When you switch back to the game, you need to do something to make it re-grab the mouse.
    For instance in Urban Terror (FPS), when you switch back to the game, the mouse behaves erratic until you press ~ for Console (which normally ungrabs the mouse) and then press it again.
    Last edited by Procyon (2012-01-23 20:14:08)

  • After updating to v. 24.0 (and restarting) ALL add-ons (regardless whether they work or not) are marked "(disabled)", and clicking Enable button does nothing

    After updating to v. 24.0 (and restarting, several times) ALL add-ons (regardless whether they work or not) are marked "(disabled)". I tried clicking "Enable" button for each add-on and nothing happened. There is only one add-on which is marked as incompatible with this version (but it was also incompatible with previous version, and so marked).
    Clicking "Update Add-ons", gives a short list of add-ons but "Install Updates" button is pale and doesn't work. I can only sort list by name or last update.
    Also, I disabled Ask Toolbar and that went well. When I click "Enable" button (button works ONLY for this add-on) it takes forever to get note: “Ask Toolbar will be enabled after you restart Firefox”, I used to get this info in seconds time before this update. (I do not really want Ask Toolbar, I just used it to see whether if I disable and then enable an add-on might do the trick.)
    Bottom line – I can not tell if add-on works (i.e. if it is enabled or disabled) unless I try using it.
    Even when I posted this question and installed Troubleshooter, it's also marked as "(disabled)"

    You're welcome
    Are this screenshots from an extension window because the built-in about:addons page looks different?

  • Has anyone figured out how to get speech recognition working with sticky keys enabled on mountain lion?

    I'm trying to use speech recognition to input text on my iMac running the latest mountain lion, 10.8.3.
    I have sticky keys enabled.
    When I try to start speaking by pressing the function key twice nothing happens. I can only get it to work if I disable sticky keys.
    The same problem occurs with all the other modifier keys as shortcut, they do not work with sticky keys.
    When I try to select a different shortcut, I am unable to select a two key combination, but am limited to one.
    If I select the F6 key, or any other single key, I am able to start speech recognition. However the second time that I press the key, it does not stop recognition and process my words. Instead, it restarts the recognition.
    Has anyone figured out how to get speech recognition working with sticky keys enabled?
    Or a way to get an individual key shortcut to start on the first press and process it on the second?
    Or a way to get key combinations to work, as specified by the help:
    Dictation On and Off
    To use Dictation, click On.
    When you’re ready to dictate text, place the insertion point where you want the dictated text to appear and press the Fn (function) key twice. When you see the lighted microphone icon and hear a beep, the microphone is ready for you to speak your text.
    Shortcut
    By default, you press the Fn (Function) key twice to start dictation. If you like, you can choose a different shortcut from the menu.
    To create a shortcut that’s not in the list, choose Customize, and then press the keys you want to use. You can press two or more keys to create your shortcut.

    I noticed with version 10.8.4 of OS X that I am now able to select F6 to activate, and the return key to complete the speech recognition. This is still different than the description of how these should function that's included in the help, but at least it's an improvement.

  • How to Add shortCut  key to  button or form In SAP BusinessOne

    Hi
    How to assign short Cut  key to  button or form ,in SAP BusinessOne using  VB.net.
    Thanks,
    Y.
    Edited by: Yughandar on Mar 10, 2011 9:32 PM

    Hi
    To set shortcut key for button , try this
    in your srf change the button caption like this
    caption="&Del line"
    this will set shortcut key (Alt+d) for the button
    Regards
    Arun

  • Change Button Name in JOptionPane.showMessageDialog

    Hello,
    I've written the following code that invokes a JOPtionPane messageDialog, when the delete button is hit in the following frame and the selectedItem in the JComboBox is Default.
    I want to change the JOPtionPane button name from OK to Close. Is there a way to do this with error message dialoges, as their is with confirmDialoges?
    Please help out.
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class MyJOptionPaneTest {
         public MyJOptionPaneTest()
              JFrame frame = new JFrame("My Frame");
              JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
              final JComboBox myComboBox = new JComboBox();
              myComboBox.setPreferredSize(new Dimension(100,20));
              myComboBox.getModel().setSelectedItem("Default");
              myComboBox.addItem("Default");
              myComboBox.addItem("Other");
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        if(myComboBox.getSelectedItem().equals("Default"))
                             JOptionPane.showMessageDialog(null, "Default cannot be deleted", "Error", JOptionPane.ERROR_MESSAGE);
              panel.add(myComboBox);
              panel.add(deleteButton);
              frame.getContentPane().add(panel);
              frame.setSize(200,100);
              frame.setResizable(false);
              frame.setVisible(true);
         public static void main(String [] args)
              MyJOptionPaneTest test = new MyJOptionPaneTest();
    }

    Hi,
    yes, I've looked at the tutorials. But there is no way to change button title for JOptionPane.showMessageDialog. Only JOptionPane.showOptionsDialog provides you w/ that feature, becuz it provides the parameter in the method.
    I was wondering if there was another way to do this for showMessageDialog.

  • "record enable" buttons not showing up in Garage Band 10.0.3 (I have selected "show record enable"- a space in the track header opens up, but the button is not present.  Same with "input moniter".

    "record enable" buttons not showing up in Garage Band 10.0.3 (I have selected "show record enable"- a space in the track header opens up, but the button is not present.  Same with "input monitor".

    Look at all the posts in the forum from users with similar problems, it happened with the last Logic update.

  • How to set Shortcut keys for button in Apex

    Hi
    Could anyone help me on how to set shortcut keys for buttons in Apex.
    I need to use say ALT + S to submit the page.
    The following thread pertaining to HTML DB refered to use ACCESS key. but that couldnt work in my case.
    Re: operation of the app. with the keyboard
    Any pointers on achieving this would be helpful.
    Thanks
    Vijay

    Hi Vijay,
    I’m afraid you must do it using javascript key listener. You can’t use action() on template based buttons because they are actually not HTML buttons but images with hyperlink.
    Key listener checks which key has been pressed down and invoke some JS function. For example, write this code in page header:
    <script>
    document.onkeydown=keyCheck;
    function keyCheck(e){
         var KeyId = (window.event) ? event.keyCode : e.keyCode;
         switch(KeyId){         
              case 113:
                   doSubmit('SAVE');
                   break;                    
              case 118:
                   alert('Hello');
                   break;
    </script>
    This script will submit page with request 'SAVE' if you press F2 or will show alert message if you press F7. Modify it to your issue.
    Regards,
    Przemek

  • Enabling Buttons

    I have disabled buttons on a page using a function and want to enable them after pressing a create button on the same page. I am trying to use another function call for the enable buttons but the create button is tied to a process and branch.
    What is the best way to call the function and have the process and branch still work.
    tks...Chris

    Hi Shijesh,
    I am using version 3.12 and have updated the enable_button() function with doSubmit('SUBMIT'); as you recommended.
    I also have my Insert Process setup with a Conditional Processing {Request = Expression1 (SUBMIT)}. My Branch is also setup with a Conditions {Request = Expression 1 (SUBMIT)}.
    I am getting the following error message related to the doSubmit('SUBMIT');
    ERR-1777: Page 5 provided no page to branch to. Please report this error to your application administrator.
    Do you have any recommendation?
    tks.. Chris

  • How to set the short cut key for buttons

    Hi
    I dont know how to set the short cut keys for the button...can u pls help me out

    Do you mean a short cut key for buttons at client side (web browser)? If yes, you could do it with JavaScript~~~ ^o^

  • Disable / re-assign key lock button on top of device

    Hi,
    I'd appreciate your help please.  How can I disable or re-assign the key lock button on the top of my 9320?
    Thanks
    Andy
    Solved!
    Go to Solution.

    Hi Welcome to the Forums!
    You can't disable or re-assign the key lock button on your 9320, But you can on the "Convenience keys", the buttons on the left and right side of your device. Here's how: Assign an application to a convenience key.
    Cheers!
    Click if you want to Thank someone. If Problem is resolved, so that others can make use of it.

  • Where's the timeline key frames button in Elements 10?

    I've just installed Premiere Elements 10 on my new iMac.  I've noticed that the add/remove key frames button on the left of the video tracks in the timeline appears only in track one and yet, in illustrations on the help pages (and in earlier versions of PE) the button appears alongside each track.
    So how do I make that button appear?
    Many thanks.

    My thanks for your interest.  I have thanked Robert for his contribution.
    Best wishes for the forum.  It's a great asset.
    Date: Tue, 22 Nov 2011 07:52:36 -0700
    From: [email protected]
    To: [email protected]
    Subject: Where's the timeline key frames button in Elements 10?
        Re: Where's the timeline key frames button in Elements 10?
        created by Bill Hunt in Premiere Elements - View the full discussion
    I would say that it's a programming Bug in the GUI display, as the Keyframe operations buttons SHOULD appear for all Tracks. However, Robert had the workaround. Bug Report. Note: PrE shows up in the Photoshop Family. Good luck, and thank you Robert, Hunt
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4040576#4040576
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4040576#4040576. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Premiere Elements by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • How to enable buttons

    Hi Friends
    How to enable buttons like "ship confirm , print Doc set , Action , Go "
    In order management shipping transaction i just query using my trip no# xxxxx... but i am seeing some of the buttons are diabled how can i enable them ? In which responsibity do i want to go for enabling it ?how to enable please suggest me
    Thanks
    AT

    Hi Friends
    Yes i got it by navigating to SET UP >Grands and role definition >grand we can define the user name and set the role as upgrade role ...by this we can make the button ennable or disable for the paricular user
    (Iam posting this solution since other can get benifited )
    Thanks
    AT

  • Partition exchange with Primary Key Enabled : is it possible ?

    Hello everybody.
    I have succeeded "exchange...INCLUDING INDEXES WITH VALIDATION" a single table with a partition when primary key of the single table and the partitioned table are both Disabled and Validated.
    I am trying now to do the same thing but with the 2 primary keys Enabled. Because of the global index générated by the Enabled PK, i "exchange ... including indexes with validation update global indexes" : it doesn't work : "ORA-14098: index mismatch for tables in ALTER TABLE EXCHANGE PARTITION".
    But indexes are the same (thanks OEM) that in the previous test, all attributes of the 2 PKs are the same.
    Thanks in advance for your help.

    For those interested. I finally found the solution elsewhere in the documentation.
    If the PK of the partitioned is enabled, the primary key of the single table has to be Disabled and Validated.

  • Primary Key radio button not working

    Hello
    I created a toplink probject on my MacOS X 10.4.6 machine using JDev 10.3.1.0.4 SU2.
    It works well, but when I click the toplink map, then I click my definition under structure to the right.
    I have a view with:
    Associated table: <popup>
    Primary keys:
    <radio button list>
    Sequencing:
    The problem is located at the radio button list of the primary keys, if I click a radio button, the XML description file is updated, but I visualy see nothing, all radio buttons are always not selected.
    As a workaround, I click the pk I want, and then I verify the XML file for correct selection.
    Hope it will be fixed.
    Regards
    Kuon

    Found a new workarround.
    Changing look from MacOS X to Oracle.
    But I hope it will get fixed, MacOS look is better with text anti-aliasing.

Maybe you are looking for