How do I detect in a focusGained event if focus was gained with backward traversal (i.e. transferFocusBackward), instead of forward traversal?
I've set up multiple custom JTables that can tab forward and backward through their cells. If a user tabs out of the table, i.e. forward on last, backward on first, I want the first or last cell selected, respectively. Selecting a cell is easy enough with the changeSelection method, but how can I tell in which direction the traversal occurred?
I can't find a direct method to access this information.
However this information does seem to be available in the FocusEvent
:
FocusListener fl = new FocusAdapter()
{
public void focusGained(FocusEvent e)
{
String eventText = e.toString();
if (eventText.contains("TRAVERSAL_FORWARD"))
System.out.println("forward");
else if (eventText.contains("TRAVERSAL_BACKWARD"))
System.out.println("backward");
}
};