Java Utililty Methods Swing ActionMap

List of utility methods to do Swing ActionMap

  1. HOME
  2. Java
  3. S
  4. Swing ActionMap

Description

The list of methods to do Swing ActionMap are organized into topic(s).

Method

void addAction(JComponent component, String kstr, AbstractAction action)
add Action
KeyStroke ks = KeyStroke.getKeyStroke(kstr);
component.getInputMap().put(ks, ks);
component.getActionMap().put(ks, action);
void addComponentAction(final JComponent component, final Action action)
Adds a component action.
final InputMap imap = component
 .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW);
final ActionMap amap = component.getActionMap();
final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
imap.put(ks, action.getValue(Action.NAME));
amap.put(action.getValue(Action.NAME), action);
void addEnterAction(JComponent c, Action a)
add Enter Action
c.getActionMap().put("enter", a);
c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
void addEnterAction(JComponent comp, Action action)
add Enter Action
comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ENTER"), action);
comp.getActionMap().put(action, action);
void addFieldsValidateAction(Action action, JComponent... components)
Add an action to execute when the validation key (Enter) is pressed on all the given components.
for (JComponent component : components) {
 addFieldValidateAction(component, action);
void addFieldValidateAction(JComponent field, Action action)
Add an action to execute when the validation key (Enter) is pressed.
field.getActionMap().put("validate", action);
field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "validate");
void attachAccelerator(Action action, JComponent component)
attach Accelerator
KeyStroke stroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
String name = (String) action.getValue(Action.NAME);
component.getInputMap(JComponent.WHEN_FOCUSED).put(stroke, name);
component.getActionMap().put(name, action);
addStrokeToName(action);
void bindAction(JComponent aComponent, String aCommand, Action anAction)
bind Action
Object o = anAction.getValue(Action.ACCELERATOR_KEY);
if (o instanceof KeyStroke)
 bindAction(aComponent, aCommand, anAction, (KeyStroke) o);
else
 throw new IllegalArgumentException("Can not bind action, it has no keystroke assigned.");
void checkActions(JComponent aComponent)
check Actions
ActionMap am = aComponent.getActionMap();
for (Object key : am.allKeys()) {
 Action action = am.get(key);
 if (action != null) {
 action.setEnabled(action.isEnabled());
ActionMap cloneActionMap(ActionMap original)
clone Action Map
ActionMap map = new ActionMap();
Object[] keys = original.keys();
if (keys != null) {
 for (Object key : keys) {
 map.put(key, original.get(key));
return map;
...


AltStyle によって変換されたページ (->オリジナル) /