Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Tab Order in Swing Java?

Tags:

java

swing

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)
like image 605
Chan Avatar asked Feb 28 '12 10:02

Chan


People also ask

How do you control tab order?

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.

How do I set tab order in Netbeans?

Right Click on the JTabbedPane->Change Order->You will get option to Move Up and Move Down which will change the order of tabs.

How is tab order determined?

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.


2 Answers

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.

like image 171
Jerome Avatar answered Oct 10 '22 05:10

Jerome


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

like image 28
jafaritaqi Avatar answered Oct 10 '22 03:10

jafaritaqi