How to make JTabbedPane not to catch Ctrl+Tab key binding?

我只是一个虾纸丫 提交于 2020-01-24 21:16:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!