简体   繁体   中英

How to set the Tab Order in Swing Java?

I want to know how to adjust the Tab order in a Swing interface. I found an example and it showed this method should do the trick but it seems that it's deprecated and not working.

getCombox("cmbFrom").setNextFocusableComponent(getCombox("cmbTo"));

Note :- Below method returns a Combox object with the Argument name. If someone knows how to do it with Netbeans IDE it would be great. I found a way to do it in Eclipse WindowBuilder but not in Netbeans IDE. Thank you.

getCombox(String s)

You can use the setFocusTraversalPolicy in your container.

FocusTraversalPolicy class is abstract and you need implement few methods which will return the container's component focus order. It will work with Tab and Shift + Tab.

if you are using netbeans select the first component that you want to be the first focused element and in properties make sure focusCycleRoot is ticked. and in the nextFocusableComponent choose the next component that you want to gain focus when you press tab and go ahead the same way for other component

Note: do not check the focusCycleRooot for the other component

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM