Package com.jidesoft.swing
Class SelectAllUtils
- java.lang.Object
-
- com.jidesoft.swing.SelectAllUtils
-
public class SelectAllUtils extends java.lang.Object
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.
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.JTextField field = new JTextField(); SelectAllUtils.install(field);
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.JComboBox comboBox = new JComboBox(); comboBox.setEditable(true); SelectAllUtils.install(comboBox);
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLIENT_PROPERTY_ONLYONCE
A client property.
-
Constructor Summary
Constructors Constructor Description SelectAllUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
install(java.awt.Component component)
Installs focus listener to all text components inside the component.static void
install(java.awt.Component component, boolean onlyOnce)
Installs focus listener to all text components inside the component.static void
uninstall(java.awt.Component component)
Uninstalls focus listener to all text components inside the component.
-
-
-
Field Detail
-
CLIENT_PROPERTY_ONLYONCE
public static final java.lang.String 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:
- Constant Field Values
-
-
Method Detail
-
install
public static void install(java.awt.Component component)
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
public static void install(java.awt.Component component, boolean onlyOnce)
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
public static void uninstall(java.awt.Component component)
Uninstalls focus listener to all text components inside the component.- Parameters:
component
- the component whichinstall(java.awt.Component)
is called.
-
-