Setting the Tab Order

A critical element of creating a user interface that will be acceptable to your users is getting the tab order of the component widgets correct. The tab order is the order in which each widget gains the input focus as the user presses the Tab key. Users expect the tab order to be logical—an order that mirrors the way they interact with the window. For example, consider a window that permits the input of name, address, city, state, and Zip Code information. In such an interface, the user expects to enter the name first, then the address, and so on. If the window opens with the focus in the address field and then shifts to the name field when the user presses the Tab key, the interface does not mirror the manner in which the user expects to enter the information.

In the absence of a specific order, as with the name and address information discussed earlier, the general rule is to have the input focus flow from top to bottom and from left to right.

How do I do that?

The tab order is set by the order in which you create the widgets:

final Text text1 = new Text(s, SWT.SINGLE | SWT.BORDER);
text1.setBounds(100,50,100,20);
final Text text2 = new Text(s, SWT.SINGLE | SWT.BORDER);
text2.setBounds(100,75,100,20);

In this case, text1 is created before text2 and thus is the first widget in the tab order.

An alternate method that can be used to set the tab order is to call the setTabList( ) method of the Composite class. Composite is a super class of Shell, so for the Text ...

Get SWT: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.