List of usage examples for java.awt Container setFocusTraversalKeys
public void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
From source file:Main.java
/** * install focus forward and backward// ww w . ja v a 2 s . c o m */ public static void installDefaultFocusHandling(Container c) { // focus TAB HashSet<KeyStroke> set = new HashSet<KeyStroke>(1); set.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); c.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set); // focus shift-TAB set = new HashSet<KeyStroke>(1); set.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); c.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set); // make input map WHEN_FOCUSED non-empty for Focus Traversal policy to work // correctly if (c instanceof JComponent) { JComponent jc = (JComponent) c; InputMap inputMapWhenFocused = jc.getInputMap(JComponent.WHEN_FOCUSED); if (inputMapWhenFocused.size() == 0) { inputMapWhenFocused.put(KeyStroke.getKeyStroke(KeyEvent.VK_STOP, KeyEvent.KEY_TYPED), "swingDummyFocusKey"); } } }