How to disable detection of ESCAPE key in JDialog?

Hi,
I've implemented a non-modal JDialog, and to be sure the user doesn't close it I call setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)However, the user can always close it by pressing the ESCAPE key.
Key binding does not work as the dialog is not a JComponent, and a KeyListener seems not to work.
Is there a way to catch the ESCAPE key?
Thanks in advance for any hint.

However, the user can always close it by pressing the ESCAPE key.Is this a new feature in JDK1.5 or JDK6?
The escape key is not supported by default in JDK1.4.2 so I'm surprised that its turned on by default in later versions.
This is how I add the funtionality in JDK1.4.2:
Action escapeAction = new AbstractAction()
     public void actionPerformed(ActionEvent e)
          System.out.println("escape");
          setVisible( false );
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
     .put(escapeKeyStroke, "escape");
getRootPane().getActionMap().put("escape", escapeAction);So, presumably you could override the default behaviour by using a dummy Action.

Similar Messages

  • How can I get the escape key to work again?

    I've used "esc" to get out of VI's insert mode for 40 years. I am not going to relearn that keystroke as "ctl-esc", period. Even if I were to do that, then I'd be typing ctl-esc on other platforms where it would not work because I have to type "esc" alone. If there is a way to fix in in System Preferences->keyboard, I cannot find it. If there is not, then it is completely 100% brain-dead wrong. I hope that's not the case.  So there is definitely a bug:
    The key-up event on the escape key does not cause the escape key code to be delivered to the active window when no other key is pressed, or
    The UI is sufficiently obtuse that the cause of the suppression cannot readily be found.
    I do hope it is merely the latter because I am compelled to use Outlook and Outlook does not work properly under OS/X 10.6.  (Our Exchange Server is rigged to only allow Outlook clients to send email outside of the company.)
    Thank you.

    The answer is:  The bug is in the UI.  Speech recognition was enabled, by default it uses the bare escape key as a "mic on" indicator, and it does not leave any trace in the keybord configuration.  So that is the bug.  It needs to leave a trace there, a la: "X Listen-for-voice-command  ^" under Mission Control.

  • How to disable detection of duplicate messages in Lion Mail?

    When Mail in Lion detects duplicate messages in a mailbox, it groups them together and shows the link in the header "x Duplicates", where x is the number of duplicate messages found. When that link is clicked the duplicate messages show in the mailbox separately. But I'd like Mail to stop grouping them together to begin with.
    Running OS X 10.7.3 and Mail 5.1

    To disable automatic grouping of duplicate messages, quit Mail then run this command in Terminal:
         defaults write com.apple.mail AlwaysShowDuplicates -bool true
    To revert to the default setting, run this command:
         defaults write com.apple.mail AlwaysShowDuplicates -bool false
    or simply delete the setting altogether with this command:
         defaults delete com.apple.mail AlwaysShowDuplicates
    If you want to see how Mail behaves with this setting enabled, but without modifying your preference file, start Mail from Terminal with this command:
         /Applications/Mail.app/Contents/MacOS/Mail -AlwaysShowDuplicates YES
    I learned of Mail's modifiability (is that a word?) from here:
         http://hints.macworld.com/article.php?story=2004101603285984
    and here:
         http://erikslab.com/2007/07/16/os-x-mailapp-logging/
    I found the AlwaysShowDuplicates option by looking for interesting words similar to 'duplicates' in the Mail executable like this:
              strings /Applications/Mail.app/Contents/MacOS/Mail | grep -i duplicat

  • How to Disable a PARTICULAR action key?

    Hi,
    I know how to turn off action keys from BIOS. What i want to is just disable the help action of the F1key. I basically want it o have no fuction (so that it would perform the assigned function for the game) like the f5 key on my Envy 15t. I use the f1 key in games, since every time i press it it opens up the help, i want to disable it. However, i do not want to disable the rest and want to be able use them without having to press the FN key. 
    I am not sure if there is a solution to this problem but i would still love to hear some suggestions.
    Thank You.

    Hi,
    If just for Windows XP: you should be able to disable the help stuff by disabling the Help and Support service. (start->type services.msc->press enter).
    And for Windows 7 (Vista could be the same):
       http://www.sevenforums.com/customization/171360-there-way-totally-disabling-f1-hotkey.html
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How to disable F1 to F12 keys in Web Browser when SWF file is in focus

    Hi all,
    Im running / loading a swf file in IE. I want to disable the
    function keys ( F1- F12 keys) in IE as I have defined special
    functions for these keys in my swf / flash file.Im using a
    javascript code to do this and the javascript code is working
    correctly.But the problem starts when the swf file is in focus,
    when swf file is in focus and if I press the F3 key the search of
    IE opens, but I have defined a special function in my swf file for
    this key, here the IE is overriding and it's taking the precedence
    in the event handling this is what I want to disable.So that I can
    catch the event in SWF file or get the Key code and run the my
    function defined for the key.
    Thanks.

    apollothethird wrote:
    When testing my applets on a Linux Web site I’m finding that I have to totally exit the browser, then open up a new browser session to see the updates on my applets. Yes. Applets can be horrible for caching. I am surprised that exiting and restarting the browser works. I usually clear the cache in the Java Console.
    ..The refresh button on the browser won’t show the new version of the jar file program. I find this consistent with Firefox, MS Internet Explorer, and Google Chrome.
    Is there some type of browser option that will allow the next jar version to be run without having to exit out of the browser to see it?
    No, but if the Java Console is open, it is pretty easy to force a refresh of the classes.
    As an aside, for a more general solution for your end users, look to launch the app. using [Java Web Start|http://java.sun.com/javase/technologies/desktop/javawebstart/index.jsp] . Updates are reliable and automatic.
    Thanks in advance for any comments on this.No worries (in advance).
    Note that my reply would have been sooner, except that I felt compelled to get that matter of the link in your post dealt with, before commenting.

  • On OS X Lion Mountain, how can I get the escape key to work?

    While typing i accidentally disabled the f keys (f1-f10) on the first row and the esc key. After trying to find a solution i manage to enable he f keys but works only after typing the fn key with an f key. The esc key still doesnt work. Can someone helpe me

    Disable the feature in System Preferences.
    http://support.apple.com/kb/HT3399

  • How to disable windows 8 f key shortcuts

    I am using windows 8 and HP Pavilion laptop.
    I am playing games that require using f keys sometimes, but these f keys do different things in the desktop or whatsoever.
    F1 opens up some kind of windows help bar, f2 makes the screen darker and f3 lighter.
    I searched HP support forums and found someone else having the same problem. I followed the instructions and went to disable my action keys in system configurations. I saved the new settings and rebooted laptop, but still those fkeys work without using fn button.
    What to do ?

    Hello JoonaNikolai,
     You state after disabling the action keys in the BIOS the F keys still work without having to use the FN key along with them, is that correct?  I will try to assist you with this.
    Can you please provide the make and model of the computer you have, if you are unsure where to locate that information have a look at this link for help.
    Please respond back at your earliest convenience.
    Thanks
    Clicking the White Kudos star on the left is a way to say Thanks!
    Clicking the 'Accept as Solution' button is a way to let others know which steps helped solve the problem!

  • Anyone know how to disable the "caps lock" key?

    I'm a klutz typist who needs to look at the keys when I type, and I often hit the caps lock key by mistake and have to go back and retype a lot. There used to be in the real old days a freeware utility to do this, but I don't know how to do it today.
    PowerBook G4 Titanium 400   Mac OS X (10.3.9)  

    Hi, Starratt, and welcome to Apple Discussions. Here are some links to possible solutions:
    http://mkaz.com/archives/86
    http://forums.macosxhints.com/archive/index.php/t-10186.html
    http://forums.cnet.com/5208-6142_102-0.html?forumID=97&threadID=199678&messageID =2150130

  • How to ENABLE detection of duplicate messages in Mavericks Mail?

    Hello,
    There was a good discussion of how to disable detection of duplicate messages in Lion mail - https://discussions.apple.com/message/18265121#18265121
    but unfortunately nothing seems to work to turn them ON in Mavericks.
    In Lion or Mt. Lion I do see duplicate messages - but in Mavericks I do not - but I want to see if there are duplicates for a variety of reasons.
    In the post referenced above none of the command line suggestions seem to make a difference. My mail perference settings are idential on each system, be it Lion, Mr. Lion or Mavericks. Settings as follows:
    Please note 'include related messages' seems to make no difference either way.
    Can anyone please tell me how to display duplicates in Mavericks. Thank you very much in advance.
    E.

    As a quick update, the following command DOES in fact show the duplicates in the mail folder:
              defaults write com.apple.mail AlwaysShowDuplicates -bool true
    So, if there are two exact messages (one sent to me at [email protected] and one forwarded to that email address and sent to me at [email protected], BOTH will show up as separate messages.
    But to be clear, what I want to see is a single message with the '1 Duplicate' indicated in the message header.
    Any way to do that in Mavericks?
    Again, thanks in advance.

  • How to disable heptic feedback vibration

    Please update me about how to disable vibration on three keys in nokia lumia 520

    You can't
    Click on the blue Star Icon below if my advice has helped you or press the 'Accept As Solution' link if I solved your problem..

  • Disable Escape key

    I want do disable my Escape key (due to a hardware defect) and use the Caps lock key instead.
    There exists a vast of tips how to map Escape to Caps lock, but what I want is:
    * disable Escape key completely (because it's pressed randomly, tea accident, laptop keyboard)
    * change the keymap files (create a new) under /usr/share/kbd/keymaps, not only use xmodmap
    I'm from Germany and use the de-latin1-nodeadkeys map.
    I tried the following:
    # jakob.map: disable Escape and map Escape to Caps lock
    include "de-latin1-nodeadkeys.map"
    keycode 1 =
    keycode 58 = Escape
    But this does not disable the Escape key.
    So, how can I completely disable that key?
    Further questions:
    * the Caps lock LED on my keyboard is still turning on and off, although it's now an Escape key -- is there a chance to change this behavior?
    * can I change the current keymap while running, or do I have to put the name in rc.conf and reboot?

    jakobm wrote:* can I change the current keymap while running, or do I have to put the name in rc.conf and reboot?
    loadkeys: it is invoked by rc.sysinit
    status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u $KEYMAP
    As for your problem you could try to remap esc to some useless key like scroll lock as it's already been suggested.
    I think loadkeys replaces the default key bindings made at boot by the kernel, so ESC is mapped to ESC because the standard american keyboard is like that and you have to specify explicitly to remove a binding, so leaving keycode 1 blank simply doesn't replace the value.

  • Can't use down key because it opens automator. Does any one know how to disable this short cut?

    Everytime I press down on down key it opens automator. It doesn't let me delete the app. I don't know what to do, it is very frustating to fill in a chart when I can't use the down key. Does any one know how to disable this short cut?

    Are you talking about the Down Arrow key? To my knowledge there is no way to use that key as a shortcut for anything. But look in the Keyboard section of System Preferences and the Keyboard shortcut tab.

  • How to disable certain keys in Macbook's keyboard

    How to disable certain keys in Macbook's keyboard? My keyboard is break down. It always type "\" key and disturb me!
    Dealer says internal keyboard need cost $120 to replace.
    So, I think can i disable "\" key? i don't want to disable keyboard, just \" key.
    Thanks for help!

    This posting shows how to remove a default Action;
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=657819

  • How to disable F1 Key in Safari?

    How to disable F1 Key in Safari?
    (from my website)

    Have a look at Safari>Preferences>Privacy.
    (The next category over from the one you displayed in your picture.)
    charlie

  • How to disable function keys?

    Hello. I would like to disable the F1, F2,F3, and F4 function keys on my HP laptop.
    They open windows help and change my brightness.
    I would like them to not open shortcuts so I can use them for gaming.
    How do I do this? I've been reading plenty of threads on it but I still dont understand...Thanks!

    Hi there ,  Thank you for visiting the HP Support Forums and Welcome! This is a great site to get answers and ask questions. I read your post on the HP Support Forums. I understand that you would like to disable your Functions Keys on your Notebook.  Here is a document I found for your called HP Notebook PCs - Disable The Fn + Function Key Combination on Certain Models. 
    Please follow these provided troubleshooting steps, re-post and let me know if it worked. Thank you! Have a great day!

Maybe you are looking for

  • How can I update an object and its nested collection- Agengy, SMP 3.0

    Hello Gurus, I have two objects: PurchaseOrders and PurchaseItems. 1 PurchaseOrder has more than 1 PurchaseItems. In my Java code, I create a Item array in PurchaseOrder object to store the PurchaseItems. What I want to do is to update the PurchaseOr

  • Authorization issues since 7.3.2

    Since upgrading to iTunes 7.3.2 I've been having issues with purchased content. I'm asked to authorize my computer, which was previously authorized and now uses up an additional slot of my 5 allowed. When I try to play a movie, I'm asked to authorize

  • Hidden EVDRE range unhides itself

    Hi experts, I have a complex input schedule with 6 EVDREs, 2 EVDREs are creating an actual input schedule and the other 4 are used to dynamically populate drop down boxes in the 2 input schedules I want to hide the code of all 6 EVDREs and the expans

  • JCO Connection error

    Hi, While giving the parameters for JCO connection in SLD(Technical System Type:- Web As Java) I am taking the destination Type as Application Server. While creating the JCO connection the JCO connection is getting  created but while testing the conn

  • Dynamic number of PL/SQL tables help!!!

    Hi, I have a PL/SQL code in which I am using PL/SQL table of tables. The number of such tables created in the code can be dynamic. At the end of the procedure I want to insert the records from those PL/SQL tables into a database table. Something like