Java examples for Swing:JComponent
install JComponent Actions
/**// www .j ava 2s. com * MySwing: Advanced Swing Utilites * Copyright (C) 2005 Santhosh Kumar T * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ //package com.java2s; import javax.swing.*; public class Main { public static void installActions(JComponent comp, Action actions[], int condition) { ActionMap actionMap = comp.getActionMap(); InputMap inputMap = comp.getInputMap(condition); for (int i = 0; i < actions.length; i++) { String name = (String) actions[i].getValue(Action.NAME); actionMap.put(name, actions[i]); inputMap.put( (KeyStroke) actions[i].getValue(Action.ACCELERATOR_KEY), name); } } public static void installActions(JComponent comp, Action actions[]) { installActions(comp, actions, JComponent.WHEN_FOCUSED); } }