Java tutorial
//package com.java2s; import javax.swing.Action; import javax.swing.JComponent; import javax.swing.KeyStroke; public class Main { /** * Binds an action to a component. Uses the <code>Action.ACTION_COMMAND_KEY</code> and <code>Action.ACCELERATOR_KEY</code> action * properties. * * @param component * the component. * @param action * the action to bind. */ public static void bindAction(JComponent component, Action action) { component.getInputMap().put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), action.getValue(Action.ACTION_COMMAND_KEY)); component.getActionMap().put(action.getValue(Action.ACTION_COMMAND_KEY), action); } }