Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
May 20, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.
Tom Yarker
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date