tags:

views:

30

answers:

2

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 tabs for moving between list and button?

+1  A: 

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);
aioobe
+1  A: 

From Java 1.4 onwards you can define FocusTraversalPolicy: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/FocusTraversalPolicy.html

fish
found my problem , i did write my own FocusTraversalPolicy and looks like it works ,but i had some hidden panel there with some buttons not visiblesorry and thank you
shay