Setting Focus Traversal Keys for the Entire Application

This example changes the focus traversal keys for the entire application. For an example of how to change the focus traversal keys for a particular component, see Setting Focus Traversal Keys in a Component.
// Change the forward focus traversal keys for the application Set set = new HashSet( KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); set.clear(); // Call clear() if you want to eliminate the current key set set.add(KeyStroke.getKeyStroke("F2")); KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set); // Change the backward focus traversal keys for the application set = new HashSet( KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); set.clear(); // Call clear() if you want to eliminate the current key set set.add(KeyStroke.getKeyStroke("F3")); KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set); // Remove all forward and backward focus traversal keys for the application set.clear(); KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set); KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.