Example usage for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager

List of usage examples for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager

Introduction

In this page you can find the example usage for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager.

Prototype

public static KeyboardFocusManager getCurrentKeyboardFocusManager() 

Source Link

Document

Returns the current KeyboardFocusManager instance for the calling thread's context.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_TYPED) {
                e.setKeyChar('a');
            }//w  w w. j  ava  2 s  .  c  o  m
            boolean discardEvent = false;
            return discardEvent;
        }
    });
}

From source file:Main.java

public static void main(String[] argv) {
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(new FocusChangeListener());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>();

    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>();

    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);

}

From source file:Main.java

public static void main(String[] argv) {
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .addVetoableChangeListener(new FocusVetoableChangeListener());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>(KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));

    set.add(KeyStroke.getKeyStroke("F3"));
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>(KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));

    set.add(KeyStroke.getKeyStroke("F2"));
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
}

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame("Test");

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addVetoableChangeListener("focusedWindow",
            new VetoableChangeListener() {
                private boolean gained = false;

                @Override//from w  w w.  jav  a2 s.  c  om
                public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
                    if (evt.getNewValue() == frame) {
                        gained = true;
                    }
                    if (gained && evt.getNewValue() != frame) {
                        frame.dispose();
                    }
                }
            });

    frame.add(new JTextField(10), BorderLayout.NORTH);
    frame.add(new JTextField(10), BorderLayout.SOUTH);

    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:UsingFocusListener.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField("A TextField");

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            System.out.println(prop);

        }//from  w  w w.j  a v  a  2 s.  c o  m
    });

    frame.add(textField, "North");
    frame.add(new JTextField(), "South");
    frame.setSize(300, 200);
    frame.setVisible(true);
}