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

The following examples show how to use javax.swing.JComponent#setFocusTraversalKeys() . 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 File: SwingHelper.java    From azure-devops-intellij with 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
Source File: ToolAdapterTabbedEditorDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
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 File: UIUtils.java    From netbeans with 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);
}