Remove a keystroke from the keys used to shift focus in or below the given component. This modifies all sets of focus traversal keys on the given component to remove the given keystroke. These sets are inherited down the component hierarchy (until a component that has a custom set itself).
(final Component component,
final KeyStroke keystroke)
| 161 | * component hierarchy (until a component that has a custom set itself). |
| 162 | */ |
| 163 | public static void killFocusTraversalBinding(final Component component, |
| 164 | final KeyStroke keystroke) { |
| 165 | int[] sets = { KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
| 166 | KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
| 167 | KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, |
| 168 | KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS }; |
| 169 | for (int set : sets) { |
| 170 | Set<AWTKeyStroke> keys = component.getFocusTraversalKeys(set); |
| 171 | // keys is immutable, so create a new set to allow changes |
| 172 | keys = new HashSet<>(keys); |
| 173 | if (set == 0) |
| 174 | keys.add(ctrlAlt('Z')); |
| 175 | |
| 176 | // If the given keystroke was present in the set, replace it with the |
| 177 | // updated set with the keystroke removed. |
| 178 | if (keys.remove(keystroke)) |
| 179 | component.setFocusTraversalKeys(set, keys); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | private static void enableBind(final JComponent component, |
| 184 | final Action action, final KeyStroke keystroke, |