Tuesday, May 22, 2012

Transfer Focus From One Component To Other In JFrame

I am working on a JFrame with few Text Fields and JTables and have defined the Focus order of components with the tab Key using the example!



I have also inhereted the jtable Class with following changes
The problem is that on reaching the jtable and when i press the Tab key the focus is not transfered to the other Component.



public class FocusTransferableJTable extends JTable {
public boolean isFocusTraversable() {
return false;
}
}


And also using the following code for jtable and jtxtArea



public static void patch(Component c) {
Set<KeyStroke>
strokes = new HashSet<KeyStroke>(Arrays.asList(KeyStroke.getKeyStroke("pressed TAB")));
c.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, strokes);
strokes = new HashSet<KeyStroke>(Arrays.asList(KeyStroke.getKeyStroke("shift pressed TAB")));
c.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, strokes);
}


Now it is working fine for jtable and jtxtArea i now need help in jTabPane and it's sub tabs and the component inside them.
Question edited with SSCCE!





No comments:

Post a Comment