• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField with automatic completion?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there something like automatic completion for Swing's JTextField?

Any hints are welcome .
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you would have to build your own.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any more hints?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DocumentListener would probably be a good tool to use while building your own.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, I'll try to put in an example later here.
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at swing labs:

http://www.swinglabs.org/demos.jsp

They provide an AutoCompleteDecorator that you can wrap around a JTextField, JComboBox or whatever.
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example of how you would use it:



* I didn't test this code
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Jonathan, this spares some time for not reinventing the wheel.

Thanks a lot .
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jonathan Janisch:
Take a look at swing labs:

http://www.swinglabs.org/demos.jsp

They provide an AutoCompleteDecorator that you can wrap around a JTextField, JComboBox or whatever.


SwingLabs is targeted at Java 5 and not Java 1.4

Any more hints
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's a comboBox with autocomplete (editor component is a textField).

http://www.orbital-computer.de/JComboBox/

you'd have to build/create your own list of autocomplete items, instead of
the combo's listModel.

have you googled for this? - I'm sure I've seen examples of this, but each example
still requires you to build your own list of what to autocomplete from.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link Michael. SwingLabs was a perfect match, if it wasn't only for Java 5 .

The point why I'm looking for a ready baked solution is very simple: reuse

This is not just a word it's a philosophy. Of course I could start to write my own Autocomplete JTextField. But I much more like to reuse . This is not because I'm too lazy for. I only don't like to reinvent the wheel on and on.

If there is a component a strategy a pattern or else which I can reuse than why should I reinvent it and not reuse it .

Sure if at the end there is nothing that I can reuse then I'm going to implement it. But it's hard to believe that there is nothing available for such a common usage of JTextField.

Regards,
Darya
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we must be talking about different descriptions of autocomplete.

I'm talking about where you type in a letter and a popup displays with the
matches of all words starting with that letter.
Type in the next letter and the number of matches decreases etc.
Eventually you select the word/entry you want, from the popup, and this is
entered into the textfield.

the textfield part is simple - it's just a matter of adding a DocumentListener
to search a list and to display a popup of matches.

the rest os this 'feature' (about 90% of it) revolves around providing/creating
the word list to search
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
we must be talking about different descriptions of autocomplete.

I'm talking about where you type in a letter and a popup displays with the
matches of all words starting with that letter ...


No, I mean exactly the behavior you just described .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!