The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > Keystrokes and Input Maps  [6 examples]

e863. Adding an InputMap to a Component

    InputMap inputMap = new InputMap();
    
    // Add a KeyStroke
    inputMap.put(KeyStroke.getKeyStroke("F2"), "actionName");
    
    inputMap.setParent(component.getInputMap(JComponent.WHEN_FOCUSED));
    component.setInputMap(JComponent.WHEN_FOCUSED, inputMap);

 Related Examples
e858. Creating a KeyStroke and Binding It to an Action
e859. Converting a KeyStroke to a String
e860. Listing the Key Bindings in a Component
e861. Sharing an InputMap or an ActionMap Between Two Components
e862. Finding a Key Binding in a Component

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.