Link to home
Start Free TrialLog in
Avatar of ai_chien
ai_chien

asked on

Focus Traversing with user action "ENTER"

Hi,

I am trying to find a way to allow users keying in fields by traversing via TAB key or ENTER key from keyboard. TAB working fine from fields to fields but users need to have ENTER for traversing as well. I found a good reference here in EE but some of the methods have deprecated.

I found these from other resources, but it claims to be 'unchecked or unsafe  operations'.
<code>
Set set = new HashSet(
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalKeys(
            KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    set.clear();   // Call clear() if you want to eliminate the current key set
    set.add(KeyStroke.getKeyStroke("ENTER"));
    KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
</code>

I try to apply above for my code but I wasn't sure if its working and how should I be traverse from 1 field to another. Any advice is appreciated. Thanks.
Avatar of ksivananth
ksivananth
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial