• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextField with automatic completion?

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there something like automatic completion for Swing's JTextField?

Any hints are welcome .
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you would have to build your own.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any more hints?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, I'll try to put in an example later here.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic