Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "John T. Dow" Subject: JDialog not consuming ESC Message-ID: X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 35 Date: Wed, 27 Apr 2011 15:29:53 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918193 96.60.20.240 (Wed, 27 Apr 2011 10:29:53 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:29:53 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:840 To: comp.lang.java.gui I have a JDialog that responds to an ESC key regardless of which component has the focus. This is what I want. However, it seems that the esc key is not consumed, because upon disposing of this dialog, when I open another, it immediately acts as if ESC has been pressed. I assume that the ESC key is not being consumed. Here's what I'm doing. Blank lines inserted for clarity. Here I show using WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, and WHEN_IN_FOCUSED_WINDOW all at once, but I've of course tried them individually. I think WHEN_ANCESTOR_OF_FOCUSED_COMPONENT is the appropriate one to use, but that didn't seem to be firing. It's late at night and I just did all three for the heck of it. One of them is working and the EscKeyPressed method is being called. That much works. KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); DialogMainPanel.getInputMap(JComponent.WHEN_FOCUSED).put(esc, "ESCAPE"); DialogMainPanel.getInputMap (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(esc, "ESCAPE"); DialogMainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(esc, "ESCAPE"); DialogMainPanel.getActionMap().put("ESCAPE", new EscKeyPressed()); John --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24