Java Code Examples for javax.swing.JComponent#setFocusTraversalKeys()

The following examples show how to use javax.swing.JComponent#setFocusTraversalKeys() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: azure-devops-intellij   File: SwingHelper.java    License: MIT License 5 votes vote down vote up
/**
 * This method sets the FocusTraversalKeys for a component to be the standard keys.
 * Use this on Tables or TextAreas where you want the tab keys to leave the control.
 *
 * @param component the component that you want to fix tab keys for
 */
public static void fixTabKeys(final JComponent component) {
    final Set<AWTKeyStroke> forward = new HashSet<AWTKeyStroke>(
            component.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    forward.add(KeyStroke.getKeyStroke("TAB"));
    component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forward);
    final Set<AWTKeyStroke> backward = new HashSet<AWTKeyStroke>(
            component.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    backward.add(KeyStroke.getKeyStroke("shift TAB"));
    component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backward);
}
 
Example 2
private static void forwardFocusWhenTabKeyReleased(JComponent aSenderComponent, JComponent aReceiverComponent) {
    ForwardFocusAction forwardFocusAction = new ForwardFocusAction("TabKeyAction", aReceiverComponent);
    aSenderComponent.setFocusTraversalKeys(0, new HashSet());
    int modifiers = 0; // '0' => no modifiers
    int keyCode = KeyEvent.VK_TAB;
    KeyStroke tabKeyReleased = KeyStroke.getKeyStroke(keyCode, modifiers, true);
    aSenderComponent.getInputMap(1).put(tabKeyReleased, forwardFocusAction.getName());
    aSenderComponent.getActionMap().put(forwardFocusAction.getName(), forwardFocusAction);
}
 
Example 3
Source Project: netbeans   File: UIUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void fixFocusTraversalKeys(JComponent component) {
    Set<AWTKeyStroke> set = component.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    set = new HashSet<AWTKeyStroke>(set);
    set.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK));
    component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
}