Example usage for javax.swing JComponent setFocusTraversalKeys

List of usage examples for javax.swing JComponent setFocusTraversalKeys

Introduction

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

Prototype

public void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) 

Source Link

Document

Sets the focus traversal keys for a given traversal operation for this Component.

Usage

From source file:Main.java

public static void setTabFocusTraversalKeys(final JComponent component) {
    component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            new HashSet<AWTKeyStroke>(Arrays.asList(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))));
    component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, new HashSet<AWTKeyStroke>(
            Arrays.asList(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))));
}

From source file:Main.java

public static void setComponentTraversalKeys(int direction, JComponent component, KeyStroke stroke) {
    Set<AWTKeyStroke> forwardKeys = component.getFocusTraversalKeys(direction);
    Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys);
    newForwardKeys.add(stroke);//from  w  ww.  java 2 s.c om
    component.setFocusTraversalKeys(direction, newForwardKeys);
}