Select On Focus TextField


Form-based applications enable users to efficently enter or update data. The default behaviour of Swing's text field is somewhat cumbersome for such applications, though. On gaining focus JTextField (and therefore ULCTextField) just places the caret at the end of the text in a text field. Usually, it is much more convenient if the entire text gets selected as soon as the text field gains focus.

This contribution demonstrates how to adapt ULCTextField. The 5.2 version is based on Etienne's PatchedUITextField class which comes with Lookup TextField. The 6.0 version doesn't need that because of the vastly improved extension API. As you can see from the source code the extension is way smaller.

Related To

How to use

You instantiate, configure, and use a ULCSelectOnFocusTextField like a ULCTextField.

How it is implemented

The UISelectOnFocusTextField class serves as a proxy to the ULCSelectOnFocusTextField class. UISelectOnFocusTextField inherits from PatchedUITextField and ULCSelectOnFocusTextField inherits from ULCTextField.

UISelectOnFocusTextField features an internal class UIJTextField which overrides the standard Swing text selection business on focus gaining. In addition, UISelectOnFocusTextField handles the additional SelectOnFocus property.

The version for ULC 6.0 directly inherits from UITextField.