Here you can find the source of fixTabKeys(final JComponent component)
Parameter | Description |
---|---|
component | the component that you want to fix tab keys for |
public static void fixTabKeys(final JComponent component)
//package com.java2s; // Licensed under the MIT license. See License.txt in the project root. import javax.swing.JComponent; import javax.swing.KeyStroke; import java.awt.AWTKeyStroke; import java.awt.KeyboardFocusManager; import java.util.HashSet; import java.util.Set; public class Main { /**/*from w w w. j av a 2s .com*/ * 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); } }