javax.swing.JTable#getActionMap ( )源码实例Demo

下面列出了javax.swing.JTable#getActionMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Adds input action map for the tmodel<p>
 * needed as <code>OnKeyPress Edit</code> in autosuggest overriding the
 * basic <code>Delete</code> key press
 *
 * @param table the target tmodel
 */
private static void clearTableSelectionOnDelete(final JTable table) {
    InputMap inputMap = table.getInputMap(WHEN_FOCUSED);
    ActionMap actionMap = table.getActionMap();
    inputMap.put(Keystroke.DELETE, "delete");
    actionMap.put("delete", new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelEditing(table);
            ClearSelection(table);
        }

    });
}
 
public static void initTMTable(JTable table) {
    InputMap imTD = table.getInputMap(WHEN_FOCUSED);
    ActionMap amTD = table.getActionMap();
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mItemEnc = new JMenuItem("Encrypt");
    popup.add(mItemEnc);
    Action enc = getEncryptAction(table);
    mItemEnc.setAccelerator(Keystroke.ENCRYPT);
    mItemEnc.addActionListener(enc);
    imTD.put(Keystroke.ENCRYPT, "encrypt");
    amTD.put("encrypt", enc);
    table.setComponentPopupMenu(popup);
    JtableUtils.addlisteners(table, Boolean.FALSE);
}
 
源代码3 项目: IrScrutinizer   文件: TableUtils.java
private void addKey(JTable table, String name, int key, int mask, Action action) {
    InputMap inputMap = table.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = table.getActionMap();
    KeyStroke keyStroke = KeyStroke.getKeyStroke(key, mask);
    inputMap.put(keyStroke, name);
    actionMap.put(name, action);
}
 
 方法所在类
 同类方法