Package com.jidesoft.swing
Class SelectAllUtils
java.lang.Object
com.jidesoft.swing.SelectAllUtils
SelectAllUtils
is a utility class to select all the text
in a text component when the component first time receives focus. It's very easy to use it.
JTextField field = new JTextField();
SelectAllUtils.install(field);
The component you pass in can be a JTextComponent or any container that contains
one or more JTextComponents. All JTextComponents will be installed such a
focus listener to select all when it gets focus for the first time. For example,
you can install it to an editable JComboBox.
JComboBox comboBox = new JComboBox();
comboBox.setEditable(true);
SelectAllUtils.install(comboBox);
Although JComboBox is not JTextComponent but it contains a JTextField so it
will still work. However please make sure call it after the call to
comboBox.setEditable(true). Otherwise it will not work because JTextField is not created
until setEditable(true) is called.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Installs focus listener to all text components inside the component.static void
Installs focus listener to all text components inside the component.static void
Uninstalls focus listener to all text components inside the component.
-
Field Details
-
CLIENT_PROPERTY_ONLYONCE
A client property. If set to Boolean.TRUE, we will only select all the text just for the first time when the component gets focus.- See Also:
-
-
Constructor Details
-
SelectAllUtils
public SelectAllUtils()
-
-
Method Details
-
install
Installs focus listener to all text components inside the component. This focus listener will select all the text when it gets focus.- Parameters:
component
- the component to make it select all when having focus. The component could be a JTextComponent or could be a container that contains one or more JTextComponents. This install method will make all JTextComponents to have this select all feature.
-
install
Installs focus listener to all text components inside the component. This focus listener will select all the text when it gets focus.- Parameters:
component
- the component to make it select all when having focus. The component could be a JTextComponent or could be a container that contains one or more JTextComponents. This install method will make all JTextComponents to have this select all feature.onlyOnce
- if true, we will only select all the text when the component has focus for the first time. Otherwise, it will always select all the text whenever the component receives focus.
-
uninstall
Uninstalls focus listener to all text components inside the component.- Parameters:
component
- the component whichinstall(java.awt.Component)
is called.
-