Swing/CompositionEnabled のバックアップの現在との差分(No.8)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/CompositionEnabled へ行く。
- 1 (2008-06-23 (月) 13:43:43)
- 2 (2008-06-23 (月) 14:54:01)
- 3 (2008-06-23 (月) 16:29:42)
- 4 (2013-01-20 (日) 23:43:47)
- 5 (2013-07-26 (金) 02:05:52)
- 6 (2013-08-20 (火) 14:21:02)
- 7 (2015-01-29 (木) 15:39:32)
- 8 (2016-08-09 (火) 13:55:10)
- 9 (2017-10-04 (水) 18:19:05)
- 10 (2019-04-09 (火) 15:46:49)
- 11 (2021-01-26 (火) 11:26:05)
- 12 (2023-12-14 (木) 10:19:23)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: CompositionEnabled title: JTableのセル編集を文字入力変換中からでも可能にする tags: [JTable, InputContext] author: aterai pubdate: 2008-06-23T13:43:43+09:00 description: IMEが直接入力以外で、一時ウィンドウが表示されていても、入力確定でセル編集を開始します。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTKG6DmuHI/AAAAAAAAAVc/WfOft65kSaQ/s800/CompositionEnabled.png --- * 概要 [#summary] `IME`が直接入力以外で、一時ウィンドウが表示されていても、入力確定でセル編集を開始します。 #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTKG6DmuHI/AAAAAAAAAVc/WfOft65kSaQ/s800/CompositionEnabled.png) * サンプルコード [#sourcecode] #code(link){{ JTable table = new JTable(model) { @Override protected boolean processKeyBinding( KeyStroke ks, KeyEvent e, int condition, boolean pressed) { boolean retValue = super.processKeyBinding(ks, e, condition, pressed); //if (!check.isSelected()) return retValue; if (KeyStroke.getKeyStroke('\t').equals(ks) || KeyStroke.getKeyStroke('\n').equals(ks)) { // if (!check.isSelected()) return retValue; if (KeyStroke.getKeyStroke('\t').equals(ks) || KeyStroke.getKeyStroke('\n').equals(ks)) { System.out.println("tab or enter typed"); return retValue; } if (getInputContext().isCompositionEnabled() && !isEditing() && !pressed && !ks.isOnKeyRelease()) { int selectedRow = getSelectedRow(); int selectedColumn = getSelectedColumn(); if (selectedRow != -1 && selectedColumn != -1 && !editCellAt(selectedRow, selectedColumn)) { if (selectedRow != -1 && selectedColumn != -1 && !editCellAt(selectedRow, selectedColumn)) { return retValue; } } return retValue; } }; //table.setSurrendersFocusOnKeystroke(true); // table.setSurrendersFocusOnKeystroke(true); }} * 解説 [#explanation] 上記のサンプルでは、以下のような設定になっています。 - KBD{Tab}やKBD{Enter}キーでのセルフォーカス移動では編集開始しない - `JTable#processKeyBinding`をオーバーライドして、入力モードが確定したら選択セルの編集開始 - `JTable#processKeyBinding(...)`メソッドをオーバーライドして入力モードが確定したら選択セルの編集開始 - インプットメソッドが起動中かどうかは`Component#getInputContext#isCompositionEnabled()`メソッドで判断可能 インプットメソッドが起動中かどうかは、`Component#getInputContext#isCompositionEnabled`メソッドで判断しています。 * 参考リンク [#reference] - [http://docs.oracle.com/javase/jp/6/technotes/guides/imf/index.html Java Input Method Framework テクノロジ] - [https://docs.oracle.com/javase/jp/8/docs/technotes/guides/imf/index.html Java Input Method Framework] - [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/im/InputContext.html#isCompositionEnabled-- InputContext#isCompositionEnabled() (Java Platform SE 8)] * コメント [#comment] #comment #comment