JComponent.WHEN_IN_FOCUSED_WINDOW : Event Queue « Event « Java






JComponent.WHEN_IN_FOCUSED_WINDOW

  


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) throws Exception {

    JButton component = new JButton();

    MyAction action = new MyAction();
    component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F2"),
        action.getValue(Action.NAME));
  }
}

class MyAction extends AbstractAction {
  public MyAction() {
    super("my action");
  }

  public void actionPerformed(ActionEvent e) {
    System.out.println("hi");

  }
}

   
    
  








Related examples in the same category

1.Use the Event queue to retrieve eventUse the Event queue to retrieve event
2.Event object has information about an event, that has happened.
3.Register several listeners for one event.
4.ActionEvent.getActionCommand()
5.Adding an InputMap to a Component
6.Event source and listener
7.Multiple sources: A listener can be plugged into several sources.
8.Using an inner ActionListener class.
9.void java.awt.Toolkit.addAWTEventListener(AWTEventListener listener, long eventMask)
10.int java.awt.event.WindowEvent.WINDOW_OPENED
11.Register action
12.Using EventQueue.invokeLater to start a Swing application