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)
Change the tab order for controls Use the following procedure to change the tab order of the controls. In the Navigation Pane, right-click the form and then click Design View. On the Design tab, in the Tools group, click Tab Order. In the Tab Order dialog box, under Section, click the section you want to change.
Right Click on the JTabbedPane->Change Order->You will get option to Move Up and Move Down which will change the order of tabs.
Control tab order is determined by the order in which controls are drawn on the screen. The first control that you draw is assigned a tab order of 1 , the next is given tab order number 2 , and so on.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With