Avoiding Tab Traversal for Non-Editable TextFields

Avoiding Tab Traversal for Non-Editable TextFields

To prevent a component from getting the focus when the Tab or shift-Tab keyboard focus traversal is used, override the isFocusTraversable method. It is often desirable to toggle a TextField in an interface so that it allows input at some times and disallows it at others. One way to do this is to disable the TextField using setEnabled(), but this approach has the disadvantage of changing the appearance of the TextField. Alternatively, you can use setEditable() to make the TextField read-only without changing its appearance. Unfortunately, disabling editing of the TextField does not prevent the Tab and shift-Tab key sequences from transferring the focus to the field. The result is that Tab and shift-Tab will transfer the focus to a TextField that cannot be edited. This behavior is annoying for users who are accustomed to tabbing through interface components, but expect the “inactive” components to be skipped. To provide a user-friendly interface, you can create a subclass of TextField, which will behave somewhat more intuitively:

 public class SmartTabTextField extends TextField {	/**	 *  If this component is not editable, it should also not receivethe focus	 *  as a result of Tab or shift-Tab being pressed.	 */	public boolean isFocusTraversable() {		return isEditable();	}}

This code does not prevent the TextField from getting the focus when it is explicitly selected, such as with a left mouse button click. However, it will prevent unexpected occurrences when the user is simply tabbing through a series of interface components.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes