JComponent: getActionMap() : JComponent « javax.swing « Java by API






JComponent: getActionMap()

  


 

import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

public class Main {
  public static void main(String[] argv) {
    JButton component = new JButton();
    NextFocusAction nextFocusAction = new NextFocusAction();

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("SPACE"),
        nextFocusAction.getValue(Action.NAME));

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("F2"),
        nextFocusAction.getValue(Action.NAME));

    component.getActionMap().put(nextFocusAction.getValue(Action.NAME), nextFocusAction);
    
  }
}

class NextFocusAction extends AbstractAction {
  public NextFocusAction() {
    super("Move Focus Forwards");
  }
  public void actionPerformed(ActionEvent evt) {
    ((Component) evt.getSource()).transferFocus();
  }
}

   
   

   
    
  








Related examples in the same category

1.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
2.JComponent.WHEN_IN_FOCUSED_WINDOW
3.JComponent: addPropertyChangeListener(PropertyChangeListener listener)
4.JComponent: addVetoableChangeListener(VetoableChangeListener listener)
5.JComponent: getAccessibleContext()
6.JComponent: getHeight()
7.JComponent: getInputMap()
8.JComponent: getTransferHandler()
9.JComponent: getWidth()
10.JComponent: getX()
11.JComponent: getY()
12.JComponent: putClientProperty(Object key, Object value)
13.JComponent: requestFocusInWindow()
14.JComponent: registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
15.JComponent: revalidate()
16.JComponent: setComponentPopupMenu(JPopupMenu popup)
17.JComponent: setFont(Font font)
18.JComponent: setFocusTraversalKeys(int arg0, Set arg1)
19.JComponent: setInputMap(int condition, InputMap map)
20.JComponent: setInputVerifier(InputVerifier inputVerifier)
21.JComponent: setOpaque(boolean isOpaque)
22.JComponent: setTransferHandler(TransferHandler newHandler)