Text Fields

Text Field Styles

VAqua supports two custom styles of text fields, which are selected by setting the JTextField.style client property. In addition, any text field used on a tool bar displays in the style of a textured button.

Setting the JTextField.style client property to round changes the text field border to have rounded corners.

Setting the JTextField.style client property to search changes the text field to display as a search field. A search field displays a magnifying glass icon, with an optional menu icon. When the search field is empty, it optionally displays a prompt. When the search field text is not empty, it displays a cancel button.

The menu icon is displayed when the text field is focused if a menu has been defined for the text field. To define a menu, set the JTextField.Search.FindPopup client property to a JPopUpMenu.

The prompt text is specified as the value of the JTextField.Search.Prompt client property. Any object may be used. It will be converted to text using the toString() method.

Action listeners may be provided that are invoked when the magnifying glass icon or the cancel button is clicked by setting the JTextField.Search.FindAction and JTextField.Search.CancelAction client properties, respectively. If the JTextField.Search.FindAction property is not defined, clicking on the magnifying glass icon will perform the text field action.

Size Options

Text fields support several size options, specified using the JComponent.sizeVariant client property with values regular (the default), small, or mini. The size option affects the default font. For the round and search styles, which have a fixed height, the fixed height depends upon the size option.

Focus Option

By default, VAqua follows the macOS convention of automatically selecting the content of a single line text field when the text component receives focus. This default behavior can be overridden for any text component by setting the JTextComponent.selectContentOnFocusGained client property to (Boolean) true or false.