Package com.jidesoft.swing
Class AutoCompletion
java.lang.Object
com.jidesoft.swing.AutoCompletion
AutoCompletion
is a helper class to make JTextComponent or JComboBox auto-complete based on a list of
known items.
There are three constructors. The simplest one is AutoCompletion(javax.swing.JComboBox)
. It takes any
combobox and make it auto completion. If you are looking for an auto-complete combobox solution, this is all you
need. However AutoCompletion
can do more than that. There are two more constructors. One is AutoCompletion(javax.swing.text.JTextComponent, Searchable)
. It will use Searchable
which is another
component available in JIDE to make the JTextCompoent auto-complete. We used Searchable here because it provides a
common interface to access the element in JTree, JList or JTable. In the other word, the known list item we used to
auto-complete can be got from JTree or JList or even JTable or any other component as long as it has Searchable
interface implemented. The last constructor takes any java.util.List and use it as auto completion list.
The only option available on AutoCompletion
is setStrict(boolean)
. If it's true, it will not
allow user to type in anything that is not in the known item list. If false, user can type in whatever he/she wants.
If the text can match with a item in the known item list, it will still auto-complete.
- Author:
- Thomas Bierhance, JIDE Software, Inc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
The document class used by AutoCompletion. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The client property for AutoCompletion instance. -
Constructor Summary
ConstructorsConstructorDescriptionAutoCompletion
(JComboBox comboBox) AutoCompletion
(JComboBox comboBox, Searchable searchable) AutoCompletion
(JTextComponent textComponent, Searchable searchable) AutoCompletion
(JTextComponent textComponent, Object[] array) AutoCompletion
(JTextComponent textComponent, List list) -
Method Summary
Modifier and TypeMethodDescriptionprotected AutoCompletion.AutoCompletionDocument
Creates AutoCompletionDocument.static AutoCompletion
getAutoCompletion
(JComponent component) When auto-completion is enabled on a text component, we will set a client property on it.Gets the underlying Searchable.protected JTextComponent
Gets the underlying text component which auto-completes.void
Installs the listeners needed for auto-completion feature.boolean
isStrict()
Gets the strict property.boolean
Gets the strict completion property.void
setStrict
(boolean strict) Sets the strict property.void
setStrictCompletion
(boolean strictCompletion) Sets the strict completion property.void
Uninstalls the listeners so that the component is not auto-completion anymore.
-
Field Details
-
CLIENT_PROPERTY_AUTO_COMPLETION
The client property for AutoCompletion instance. When AutoCompletion is installed on a text component, this client property has the AutoCompletion.- See Also:
-
-
Constructor Details
-
AutoCompletion
-
AutoCompletion
-
AutoCompletion
-
AutoCompletion
-
AutoCompletion
-
-
Method Details
-
uninstallListeners
public void uninstallListeners()Uninstalls the listeners so that the component is not auto-completion anymore. -
installListeners
public void installListeners()Installs the listeners needed for auto-completion feature. Please note, this method is already called when you create AutoCompletion. Unless you calleduninstallListeners()
, there is no need to call this method yourself. -
createDocument
Creates AutoCompletionDocument.- Returns:
- the AutoCompletionDocument.
-
isStrict
public boolean isStrict()Gets the strict property.- Returns:
- the value of strict property.
-
setStrict
public void setStrict(boolean strict) Sets the strict property. If true, it will not allow user to type in anything that is not in the known item list. If false, user can type in whatever he/she wants. If the text can match with a item in the known item list, it will still auto-complete.- Parameters:
strict
-
-
isStrictCompletion
public boolean isStrictCompletion()Gets the strict completion property.- Returns:
- the value of strict completion property.
- See Also:
-
setStrictCompletion
public void setStrictCompletion(boolean strictCompletion) Sets the strict completion property. If true, in case insensitive searching, it will always use the exact item in the Searchable to replace whatever user types. For example, when Searchable has an item "Arial" and user types in "AR", if this flag is true, it will auto-completed as "Arial". If false, it will be auto-completed as "ARial". Of course, this flag will only make a difference if Searchable is case insensitive.- Parameters:
strictCompletion
-
-
getTextComponent
Gets the underlying text component which auto-completes.- Returns:
- the underlying text component.
-
getSearchable
Gets the underlying Searchable. If you use the constructorAutoCompletion(javax.swing.text.JTextComponent, Searchable)
, the return value will be the Searchable you passed in. If you use the other twoconstructorss, internally we will still create a Searchable. If so, this Searchable will be returned.- Returns:
- the Searchable.
-
getAutoCompletion
When auto-completion is enabled on a text component, we will set a client property on it. This method will look for this client property and return you the instance of the AutoCompletion that is installed on the component.- Parameters:
component
- the component.- Returns:
- the AutoCompletion. If null, it means there is no AutoCompletion installed.
-