Search code examples
javaswingfocusjtextfield

Change default "tab" action (transferfocus)


in Java SWING the "Tab" key globally transfers the focus between all components. Is it possible to modify this "default" behavior somehow?

So instead of having the "Tab" key change the focus, I want the "Enter" key doing it.

Thanks in advance!


Solution

  • to change the focusTraversalSystem takes a lot of work to do. I suggest to add an actionListener on the panel where it holds all the swing components and check the key pressed if it is enter just change the focus on the next element that has the tabFocus variable + 1( you need to put the components in an array to loop or use a native swing method if applicable).