Package org.jdesktop.swingx.autocomplete
Class AutoCompleteDecorator
- java.lang.Object
-
- org.jdesktop.swingx.autocomplete.AutoCompleteDecorator
-
public class AutoCompleteDecorator extends java.lang.Object
This class contains only static utility methods that can be used to set up automatic completion for some Swing components.Usage examples:
JComboBox comboBox = [...]; AutoCompleteDecorator.decorate(comboBox); List items = [...]; JTextField textField = [...]; AutoCompleteDecorator.decorate(textField, items); JList list = [...]; JTextField textField = [...]; AutoCompleteDecorator.decorate(list, textField);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AutoCompleteDecorator.NonStrictBackspaceAction
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<java.lang.String>
COMBO_BOX_ACTIONS
private static java.lang.Object
errorFeedbackAction
A TextAction that provides an error feedback for the text component that invoked the action.
-
Constructor Summary
Constructors Modifier Constructor Description private
AutoCompleteDecorator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static AutoCompleteDocument
createAutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor, boolean strictMatching, ObjectToStringConverter stringConverter, javax.swing.text.Document delegate)
static void
decorate(javax.swing.JComboBox comboBox)
Enables automatic completion for the given JComboBox.static void
decorate(javax.swing.JComboBox comboBox, ObjectToStringConverter stringConverter)
Enables automatic completion for the given JComboBox.static void
decorate(javax.swing.JList list, javax.swing.text.JTextComponent textComponent)
Enables automatic completion for the given JTextComponent based on the items contained in the given JList.static void
decorate(javax.swing.JList list, javax.swing.text.JTextComponent textComponent, ObjectToStringConverter stringConverter)
Enables automatic completion for the given JTextComponent based on the items contained in the given JList.static void
decorate(javax.swing.text.JTextComponent textComponent, java.util.List<?> items, boolean strictMatching)
Enables automatic completion for the given JTextComponent based on the items contained in the given List.static void
decorate(javax.swing.text.JTextComponent textComponent, java.util.List<?> items, boolean strictMatching, ObjectToStringConverter stringConverter)
Enables automatic completion for the given JTextComponent based on the items contained in the given List.static void
decorate(javax.swing.text.JTextComponent textComponent, AutoCompleteDocument document, AbstractAutoCompleteAdaptor adaptor)
Decorates a given text component for automatic completion using the given AutoCompleteDocument and AbstractAutoCompleteAdaptor.private static void
installMap(javax.swing.InputMap componentMap, boolean strict)
(package private) static void
undecorate(javax.swing.JComboBox comboBox)
(package private) static void
undecorate(javax.swing.JList list)
(package private) static void
undecorate(javax.swing.text.JTextComponent textComponent)
-
-
-
Field Detail
-
COMBO_BOX_ACTIONS
private static final java.util.List<java.lang.String> COMBO_BOX_ACTIONS
-
errorFeedbackAction
private static final java.lang.Object errorFeedbackAction
A TextAction that provides an error feedback for the text component that invoked the action. The error feedback is most likely a "beep".
-
-
Method Detail
-
installMap
private static void installMap(javax.swing.InputMap componentMap, boolean strict)
-
createAutoCompleteDocument
static AutoCompleteDocument createAutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor, boolean strictMatching, ObjectToStringConverter stringConverter, javax.swing.text.Document delegate)
-
decorate
public static void decorate(javax.swing.JComboBox comboBox)
Enables automatic completion for the given JComboBox. The automatic completion will be strict (only items from the combo box can be selected) if the combo box is not editable.- Parameters:
comboBox
- a combo box- See Also:
decorate(JComboBox, ObjectToStringConverter)
-
decorate
public static void decorate(javax.swing.JComboBox comboBox, ObjectToStringConverter stringConverter)
Enables automatic completion for the given JComboBox. The automatic completion will be strict (only items from the combo box can be selected) if the combo box is not editable.Note: the
AutoCompleteDecorator
will alter the state of theJComboBox
to be editable. This can cause side effects with layouts and sizing.JComboBox
caches the size, which differs depending on the component's editability. Therefore, if the component's size is accessed prior to being decorated and then the cached size is forced to be recalculated, the size of the component will change.Because the size of the component can be altered (recalculated), the decorator does not attempt to set any sizes on the supplied
JComboBox
. Users that need to ensure sizes of supplied combos should take measures to set the size of the combo.- Parameters:
comboBox
- a combo boxstringConverter
- the converter used to transform items to strings
-
undecorate
static void undecorate(javax.swing.JComboBox comboBox)
-
decorate
public static void decorate(javax.swing.JList list, javax.swing.text.JTextComponent textComponent)
Enables automatic completion for the given JTextComponent based on the items contained in the given JList. The two components will be synchronized. The automatic completion will always be strict.- Parameters:
list
- a JList containing the items for automatic completiontextComponent
- the text component that will be enabled for automatic completion
-
decorate
public static void decorate(javax.swing.JList list, javax.swing.text.JTextComponent textComponent, ObjectToStringConverter stringConverter)
Enables automatic completion for the given JTextComponent based on the items contained in the given JList. The two components will be synchronized. The automatic completion will always be strict.- Parameters:
list
- a JList containing the items for automatic completiontextComponent
- the text component that will be used for automatic completionstringConverter
- the converter used to transform items to strings
-
undecorate
static void undecorate(javax.swing.JList list)
-
decorate
public static void decorate(javax.swing.text.JTextComponent textComponent, java.util.List<?> items, boolean strictMatching)
Enables automatic completion for the given JTextComponent based on the items contained in the given List.- Parameters:
textComponent
- the text component that will be used for automatic completion.items
- contains the items that are used for autocompletionstrictMatching
- true, if only given items should be allowed to be entered
-
decorate
public static void decorate(javax.swing.text.JTextComponent textComponent, java.util.List<?> items, boolean strictMatching, ObjectToStringConverter stringConverter)
Enables automatic completion for the given JTextComponent based on the items contained in the given List.- Parameters:
items
- contains the items that are used for autocompletiontextComponent
- the text component that will be used for automatic completion.strictMatching
- true, if only given items should be allowed to be enteredstringConverter
- the converter used to transform items to strings
-
decorate
public static void decorate(javax.swing.text.JTextComponent textComponent, AutoCompleteDocument document, AbstractAutoCompleteAdaptor adaptor)
Decorates a given text component for automatic completion using the given AutoCompleteDocument and AbstractAutoCompleteAdaptor.- Parameters:
textComponent
- a text component that should be decorateddocument
- the AutoCompleteDocument to be installed on the text componentadaptor
- the AbstractAutoCompleteAdaptor to be used
-
undecorate
static void undecorate(javax.swing.text.JTextComponent textComponent)
-
-