Filter next focus components
I want to filter the next focus componenet using the tab key
for example , i dont want to focus JLabel
, JScrollPane
, JScrollBar
button, JPanel
, etc...
How can i do that dynamically without the programmer to handle the focus?
Here is what i did :
JFrame frame = new JFrame("");
frame.setFocusTraversalPolicy(new JTPCFocusTraversalPolicy());
public class JTPCFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
protected boolean accept(Component aComponent) {
return !JTPCGUIUtils.getInstance().filterCompoenent(aComponent);
}
}
I had a case of a JList
and a JButton
, but i have to press tab 4 times for moving between thous components.
In my case how can i make only 2 tab开发者_Python百科s for moving between list and button?
From Java 1.4 onwards you can define FocusTraversalPolicy.
Have a look at the examples at http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
The check box was removed from the focus cycle with this line of code:
togglePolicy.setFocusable(false);
精彩评论