devxlogo

Tabbing Between Components

Tabbing Between Components

With Java 1.1, the Tab key will cause the focus to step through those Components in a Container which can accept user input. Components such as Labels, which do not expect input, are skipped. The order of the tab sequence is generally the order in which the Components were passed to the Container’s add method. By extending a Component’s class you can provide control of when an instance can accept the focus, or whether it does so at all. In your Component class, add a variable as follows:

     private boolean tabbable;

Then add a pair of methods:

     public boolean isFocusTraversable() {        return tabbable;    }    public void setFocusTraversable(boolean tab_ok) {        tabbable = tab_ok;    }

The first of these is used when the Tab key is hit, to determine whether the Component can accept the focus, so you must give it the expected name, isFocusTraversable.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist