public class AutoCompletion extends Object
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.
Modifier and Type | Class | Description |
---|---|---|
protected class |
AutoCompletion.AutoCompletionDocument |
The document class used by AutoCompletion.
|
Modifier and Type | Field | Description |
---|---|---|
static String |
CLIENT_PROPERTY_AUTO_COMPLETION |
The client property for AutoCompletion instance.
|
Constructor | Description |
---|---|
AutoCompletion(JComboBox comboBox) |
|
AutoCompletion(JComboBox comboBox,
Searchable searchable) |
|
AutoCompletion(JTextComponent textComponent,
Searchable searchable) |
|
AutoCompletion(JTextComponent textComponent,
Object[] array) |
|
AutoCompletion(JTextComponent textComponent,
List list) |
Modifier and Type | Method | Description |
---|---|---|
protected AutoCompletion.AutoCompletionDocument |
createDocument() |
Creates AutoCompletionDocument.
|
static AutoCompletion |
getAutoCompletion(JComponent component) |
When auto-completion is enabled on a text component, we will set a client property on it.
|
Searchable |
getSearchable() |
Gets the underlying Searchable.
|
protected JTextComponent |
getTextComponent() |
Gets the underlying text component which auto-completes.
|
void |
installListeners() |
Installs the listeners needed for auto-completion feature.
|
boolean |
isStrict() |
Gets the strict property.
|
boolean |
isStrictCompletion() |
Gets the strict completion property.
|
void |
setStrict(boolean strict) |
Sets the strict property.
|
void |
setStrictCompletion(boolean strictCompletion) |
Sets the strict completion property.
|
void |
uninstallListeners() |
Uninstalls the listeners so that the component is not auto-completion anymore.
|
public static final String CLIENT_PROPERTY_AUTO_COMPLETION
public AutoCompletion(JComboBox comboBox)
public AutoCompletion(JComboBox comboBox, Searchable searchable)
public AutoCompletion(JTextComponent textComponent, Searchable searchable)
public AutoCompletion(JTextComponent textComponent, List list)
public AutoCompletion(JTextComponent textComponent, Object[] array)
public void uninstallListeners()
public void installListeners()
uninstallListeners()
, there is no need to call this method
yourself.protected AutoCompletion.AutoCompletionDocument createDocument()
public boolean isStrict()
public void setStrict(boolean strict)
strict
- public boolean isStrictCompletion()
setStrictCompletion(boolean)
public void setStrictCompletion(boolean strictCompletion)
strictCompletion
- protected JTextComponent getTextComponent()
public Searchable getSearchable()
AutoCompletion(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.public static AutoCompletion getAutoCompletion(JComponent component)
component
- the component.