Example usage for javax.swing JComponent WHEN_FOCUSED

List of usage examples for javax.swing JComponent WHEN_FOCUSED

Introduction

In this page you can find the example usage for javax.swing JComponent WHEN_FOCUSED.

Prototype

int WHEN_FOCUSED

To view the source code for javax.swing JComponent WHEN_FOCUSED.

Click Source Link

Document

Constant used for registerKeyboardAction that means that the command should be invoked when the component has the focus.

Usage

From source file:Main.java

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);

    System.out.println(inputMap.getParent());

}

From source file:Main.java

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);

    System.out.println(inputMap.size());

}

From source file:Main.java

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);

    System.out.println(inputMap.allKeys().length);

}

From source file:Main.java

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);

    System.out.println(inputMap.get(KeyStroke.getKeyStroke("F2")));

}

From source file:Main.java

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);

    System.out.println(inputMap.keys().length);

}

From source file:Main.java

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);

    inputMap.remove(KeyStroke.getKeyStroke("F2"));

}

From source file:Main.java

public static void main(String[] argv) {
    JButton component = new JButton();
    PrevFocusAction prevFocusAction = new PrevFocusAction();
    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift F2"),
            prevFocusAction.getValue(Action.NAME));
    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift SPACE"),
            prevFocusAction.getValue(Action.NAME));
    component.getActionMap().put(prevFocusAction.getValue(Action.NAME), prevFocusAction);
}

From source file:Main.java

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);

}

From source file:Main.java

public static void main(String[] argv) {
    InputMap im = new JTextArea().getInputMap(JComponent.WHEN_FOCUSED);
    im.put(KeyStroke.getKeyStroke("F2"), "actionName");

    ActionMap am = new JTextArea().getActionMap();
    am.put("actionName", new AbstractAction("actionName") {
        public void actionPerformed(ActionEvent evt) {
            System.out.println((JTextComponent) evt.getSource());
        }/*from w w  w . j  a v a 2s.  com*/
    });
    im.put(KeyStroke.getKeyStroke("F3"), "actionName2");
    am.put("actionName2", new AbstractAction("actionName2") {
        public void actionPerformed(ActionEvent evt) {
            System.out.println((JTextComponent) evt.getSource());
        }
    });
    JButton component1 = new JButton("button 1");
    JButton component2 = new JButton("button 2");

    component1.setInputMap(JComponent.WHEN_FOCUSED, im);
    component2.setInputMap(JComponent.WHEN_FOCUSED, im);

    component1.setActionMap(am);
    component2.setActionMap(am);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextField component = new JTextField(10);

    // Override letter a
    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("typed a"), "actionName");

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0),
            "actionName");

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("typed X"), "none");

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift pressed SPACE"),
            "actionName");

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "none");

    MyAction action = new MyAction();

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

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