Swing/InputMap のバックアップソース(No.26)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/InputMap へ行く。
- 1 (2005-04-28 (木) 04:32:54)
- 2 (2005-10-11 (火) 15:11:06)
- 3 (2006-02-27 (月) 16:05:22)
- 4 (2006-04-01 (土) 04:03:52)
- 5 (2006-10-12 (木) 17:40:11)
- 6 (2007-03-06 (火) 03:38:09)
- 7 (2007-07-18 (水) 12:40:25)
- 8 (2007-12-12 (水) 01:41:01)
- 9 (2007-12-12 (水) 14:04:57)
- 10 (2007-12-12 (水) 15:53:15)
- 11 (2007-12-17 (月) 06:43:19)
- 12 (2007-12-17 (月) 11:39:17)
- 13 (2008-09-03 (水) 01:12:31)
- 14 (2009-01-09 (金) 22:04:41)
- 15 (2010-06-17 (木) 17:28:06)
- 16 (2011-04-20 (水) 18:31:55)
- 17 (2013-04-05 (金) 17:56:30)
- 18 (2013-07-26 (金) 01:07:45)
- 19 (2013-09-01 (日) 01:40:04)
- 20 (2013-09-13 (金) 20:45:00)
- 21 (2014-11-01 (土) 00:46:09)
- 22 (2014-11-25 (火) 03:03:31)
- 23 (2015-10-29 (木) 16:21:56)
- 24 (2016-09-02 (金) 12:24:46)
- 25 (2017-03-31 (金) 16:13:03)
- 26 (2017-11-02 (木) 15:34:40)
- 27 (2018-03-14 (水) 17:20:03)
- 28 (2020-03-18 (水) 22:11:47)
- 29 (2021-09-19 (日) 10:55:00)
- 30 (2022-08-20 (土) 22:15:25)
--- category: swing folder: InputMap title: JDialogをESCキーで閉じる tags: [JDialog, InputMap, ActionMap] author: aterai pubdate: 2004-03-15T08:18:43+09:00 description: KBD{Esc}キーを押すと閉じるJDialogを作成します。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTOj22ObUI/AAAAAAAAAck/b5izKCmGkHk/s800/InputMap.png --- * 概要 [#summary] KBD{Esc}キーを押すと閉じる`JDialog`を作成します。大部分を[https://community.oracle.com/thread/1488562 Swing (Archive) - JDialog says ESC key is already registered--where?]から、そのまま引用しています。 #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTOj22ObUI/AAAAAAAAAck/b5izKCmGkHk/s800/InputMap.png) * サンプルコード [#sourcecode] #code(link){{ final JDialog dialog = new JDialog(frame, "title", true); AbstractAction act = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; InputMap imap = dialog.getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close-it"); dialog.getRootPane().getActionMap().put("close-it", act); }} * 解説 [#explanation] `JOptionPane.showMessageDialog()`メソッドなどで作成したダイアログは、KBD{Esc}キーを押すと閉じますが、デフォルトの`JDialog`の場合はそのような設定はされていません。`JDialog`でKBD{Esc}キーを押すと閉じるようにするには、`InputMap`などを使ってアクションを設定する必要があります。 * 参考リンク [#reference] - [https://community.oracle.com/thread/1488562 Swing (Archive) - JDialog says ESC key is already registered--where?] - [https://community.oracle.com/thread/1490398 Swing (Archive) - ESC Key to Close a JFrame] - [[JComponentのKeyBinding一覧を取得する>Swing/KeyBinding]] * コメント [#comment] #comment - メモ: [http://www.javaroad.jp/bbs/answer.jsp?q_id=20100528123134643 Javaの道>掲示板(JDialogが最小化されてしまう)]。 %% `JDK 1.7.0`だと、`JDialog`などの`TitleBar`を右クリックすると、「`Java Result: -1073741819`」で落ちる?%% -- &user(aterai); &new{2010-06-17 (木) 17:28:06}; -- かなり前から再現しないのに消し忘れていた。 `Nvidia`のドライバのせい? [http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6458746 Bug ID: JDK-6458746 OGL: mustang b94 doesn't work correctly with JDialog (Nvidia, 91.31, Windows)] -- &user(aterai); &new{2013-09-13 (金) 20:45:00}; #comment