问题
When I press Ctrl
+Tab
, selected tab in JTabbedPane
receives focus.
But I want to remove this key binding. So I have my own action for key binding Ctrl+Tab. It is assigned to JTabbedPane.
But it's not fired because this key binding still focuses current tab.
回答1:
So I have my own action for key binding Ctrl+Tab. It is assigned to JTabbedPane.
Did you use the proper InputMap when you assigned the Key Binding. Most LAF's will use the JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
InputMap.
See Key Bindings for a list of the bindings for your LAF.
If the Key Binding don't work then another option might be to remove Ctrl-Tab as a focus traversal key from your tabbed pane:
Set newForwardKeys = new HashSet();
newForwardKeys.add( KeyStroke.getKeyStroke("TAB") );
tabbedPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
来源:https://stackoverflow.com/questions/23228448/how-to-make-jtabbedpane-not-to-catch-ctrltab-key-binding