Java Swing Tutorial - Java InputMap.setParent(InputMap map)








Syntax

InputMap.setParent(InputMap map) has the following syntax.

public void setParent(InputMap map)

Example

In the following code shows how to use InputMap.setParent(InputMap map) method.

/*from   w ww. ja v  a2s  .co  m*/

import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

public class Main {
  public static void main(String[] argv) throws Exception {
    InputMap inputMap = new InputMap();

    inputMap.put(KeyStroke.getKeyStroke("F2"), "actionName");

    JButton component = new JButton("button");
    
    inputMap.setParent(component.getInputMap(JComponent.WHEN_FOCUSED));
    component.setInputMap(JComponent.WHEN_FOCUSED, inputMap);

  }
}