|
Replies:
6
-
Last Post:
Jul 5, 2006 1:25 PM
by: reden
|
|
|
|
|
|
|
AutoCompleteDecorator w/JComboBox
Posted:
Jun 26, 2006 9:04 AM
|
|
|
import javax.swing.*; import org.jdesktop.swingx.autocomplete.*;
public class AutoBug extends JFrame { public static void main(String argv[]) { new AutoBug(); }
public AutoBug() { super();
String items[] = {"1", "12", "123", "2", "21", "213"}; JComboBox combo = new JComboBox(items);
combo.setEditable(false); AutoCompleteDecorator.decorate(combo); combo.setSelectedItem("123");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); add(combo); pack(); setVisible(true); } }
If you run above, "1" and "12" cannot be selected from the keyboard because "123" is the current selection. I believe the problem is that Backspace is never destructive when in strict (not editable) mode. When "123" is shown and the caret is at the end of the line, if the user hits Backspace, "123" is still fully visible. However, IMO that as long as something shorter than "123" exists, then that item should be shown - "12". Things are going to get weird because if you only have "1" and "123", then what happens when the user hits backspace on "123" - should it go to "1" (yes, it should!).
Steve
|
|
|
|
|
|
|
|
|
Re: AutoCompleteDecorator w/JComboBox
Posted:
Jun 29, 2006 7:38 AM
in response to: sbusch
|
|
|
Steve,
actually I already replied, but for some reason my response never showed up on the forum or on the list?! Anyway, straight from my outbox...
Hi Steve,
thanks for pointing this out! What do you think about changing the mechanism as follows:
1. If an item exactly matches the current input (that is the string shown in the editor apart from the selected part), select this item. 2. If the currently selected item partially matches the current input, select this item. 3. Select the first item that partially matches the current input.
I'll try to set this up, so we can compare both versions.
Thomas
|
|
|
|
|
|
|
|
Re: AutoCompleteDecorator w/JComboBox
Posted:
Jun 29, 2006 8:43 AM
in response to: bierhance
|
|
|
Thomas,
After using AutoCompleteDecorator using 5000+ items, both in editable and non-editable mode, I'd like to think I'm using in a fairly extreme way.
First off, the editable mode works near perfectly. The only enhancement I can think of is allowing easy access to the combobox editor, where one could, e.g., only allow digits, or auto-convert lower to upper case.
Back to non-editable/strict mode. Why can it more-or-less act like editable mode, where backspace is always destructive? The big difference is that it will do so if there's a match? The only exception as I've stated was the a backspace for "123" to "1" is permissable only if the carat is at end of the line.
This may exactly be what you're saying, but it just seems like you can share a lot of the editable mode code.
|
|
|
|
|
|
|
|
Re: AutoCompleteDecorator w/JComboBox
Posted:
Jul 1, 2006 2:23 AM
in response to: sbusch
|
|
|
sbusch,
Glazed Lists has had a solution for autocompletion for a little while now. It includes filtering the ComboBoxModel as you type into the ComboBoxEditor, so it might be worthwhile checking out if you have 5000+ items in your model. The behaviour is meant to mimic that of the Firefox URL address picker which narrows your URL history as you enter text.
It supports a strict-mode that should behave correctly with your numeric model data.
It decorates a standard JComboBox with autocompleting and model filtering behaviour without replacing the UI Delegate, so you have complete access to everything on the JComboBox and, with few exceptions, can install custom versions of anything you like. For example, you could install a custom Document that only accepts digits or converts the case of the text.
They have a screencast demonstrating the API usage here, so you can figure out if it is right for you in about 15 minutes of watching video: http://publicobject.com/glazedlistsdeveloper/screencasts/autocompletesupport/
James
|
|
|
|
|
|
|
|
Re: AutoCompleteDecorator w/JComboBox
Posted:
Jul 1, 2006 6:42 AM
in response to: jplemieux
|
|
|
James,
Glazed Lists is exactly what the doctor ordered (and then some). Gosh, a meeting of minds between Swingx and Glazed Lists would be nice .
Thanks.
Steve
|
|
|
|
|
|
|
|
Re: AutoCompleteDecorator w/JComboBox
Posted:
Jul 5, 2006 1:25 PM
in response to: sbusch
|
|
|
> Gosh, a meeting of minds between Swingx > and Glazed Lists would be nice .
Seconded. Something like GlazedLists' EventList in the JDK core would open up a world of possibilities (well, I guess it would allow all the other stuff in GlazedLists )
|
|
|
|
|