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: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTO1Qi0Y2I/AAAAAAAAAdA/yMsuc2sjSKg/s800/KeyBinding.png

概要

JComponentから、ActionMapInputMapを取得し、KeyBindingの一覧表を作成します。
KeyBinding.png

サンプルコード

#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で選択されたコンポーネントに割り当てられているデフォルトのKeyBindingJTableに一覧表示できます。

参考リンク

参考リンク

コメント

  • このサンプルは、properties.xml の、compile.source を1.5にして、MainPanel.java の table.setAutoCreateRowSorter(true); をコメントアウトすれば、JDK 1.5 でも動作するはず。 -- aterai

コメント