Swing/KeyBinding のバックアップの現在との差分(No.5)
TITLE:JComponentのKeyBinding一覧を取得する
Posted by aterai at 2008-08-18
JComponentのKeyBinding一覧を取得する
JComponentから、ActionMap、InputMapを取得し、KeyBindingの一覧表を作成します。Mapper.javaをベースにしてUIを変更しています。- category: swing folder: KeyBinding title: JComponentのKeyBinding一覧を取得する tags: [JComponent, ActionMap, InputMap] author: aterai pubdate: 2008-08-18T11:17:11+09:00 description: JComponentから、ActionMap、InputMapを取得し、KeyBindingの一覧表を作成します。 image:
概要
JComponent
から、ActionMap
、InputMap
を取得し、KeyBinding
の一覧表を作成します。
- &jnlp;
- &jar;
- &zip;
Screenshot
Advertisement
サンプルコード
#spanend
#spandel
final List<Integer> focusType = Arrays.asList(
#spanend
JComponent.WHEN_FOCUSED, JComponent.WHEN_IN_FOCUSED_WINDOW,
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
List<Integer> focusType = Arrays.asList(
#spanend
JComponent.WHEN_FOCUSED, JComponent.WHEN_IN_FOCUSED_WINDOW,
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
table.setAutoCreateRowSorter(true);
#spandel
JPanel p = new JPanel(new GridLayout(2,1,5,5));
#spanend
#spandel
p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
#spanend
#spanadd
JPanel p = new JPanel(new GridLayout(2, 1, 5, 5));
#spanend
#spanadd
p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
#spanend
p.add(componentChoices);
p.add(new JButton(new AbstractAction("show") {
public void actionPerformed(ActionEvent e) {
model.setRowCount(0);
JComponent c = ((JComponentType)componentChoices.getSelectedItem()).component;
for(Integer f:focusType) {
loadBindingMap(f, c.getInputMap(f), c.getActionMap());
}
@Override public void actionPerformed(ActionEvent e) {
model.setRowCount(0);
JComponent c = ((JComponentType) componentChoices.getSelectedItem()).component;
for (Integer f: focusType) {
loadBindingMap(f, c.getInputMap(f), c.getActionMap());
}
}
}));
解説
上記のサンプルでは、JComboBoxで選択されたコンポーネントに割り当てられているデフォルトのKeyBindingを、JTableに表示することができます。解説
上記のサンプルでは、JComboBox
で選択されたコンポーネントに割り当てられているデフォルトのKeyBinding
をJTable
に一覧表示できます。
参考リンク
- Miscellaneous Tools - Java Swing Utilities
- Mapper.java
-
元サイト?が何処だったか分からなくなってしまったので、ファイルへの直接リンクになっています。
- How to Use Key Bindings (The Java™ Tutorials)
参考リンク
コメント
- このサンプルは、properties.xml の、compile.source を1.5にして、MainPanel.java の table.setAutoCreateRowSorter(true); をコメントアウトすれば、JDK 1.5 でも動作するはず。 -- aterai
コメント
- メールで質問がきたので追記: このサンプルは
properties.xml
のcompile.source
を1.5
にして、MainPanel.java
のtable.setAutoCreateRowSorter(true);
をコメントアウトすればJDK 1.5
でも動作します。 -- aterai -
JFileChooser
をコメントアウトしてWeb Start
でも実行できるように修正。 -- aterai