Predictive typing in JTextField

Hi All
I am currently working on A GUI Swing interface.
I want to create a textfield that could process predictive typing.
For example, I have a vector of strings (allowed words to type in). As soon as the user starts entering some characters into the text field, my program should check for existing words in the vector starting with the same characters entered by the user. Then, it could set the text in the text field with the existing word or pop up a window with all the available words starting with these characters and give the user the choice.
Any idea how I could start implementing this? Any help would be greatly appreciated.

Many thanks armalcom for your reply.
I tried your suggestion, but I have some problems.
It seems that when the user types a key, the keyTyped method is called but the getText() method returns the text before the user typed.
Example: if the textfield was empty before and the user types "h", the getText() method returns an empty string. If the user types "e" after the "h", the getText() method returns "h" and so on. Does anyone have any idea how to solve this? I tried the keyReleased method but still it does not work.
Below is my code:
     JFrame frame=new JFrame("Test");
     final JTextField txtField= new JTextField();
     txtField.addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent e)
              String gText=txtField.getText();
              String word;
              for(int i=0;i<values.size();i++) {
               word=(String) values.elementAt(i);
               if((word.indexOf(gText))!=-1) {
                   txtField.setText(word);
     frame.getContentPane().add(txtField);
     frame.setVisible(true);
     frame.pack();

Similar Messages

  • Predictive typing problem in ios 8.1.2

    I think predictive typing is not good after updating ios 8.1.3. What's happening ? I turned on and off again and again, but still the same. Why?

    It works for me. What is not working?

  • Predictive typing/ history is not coming up in location bar

    I used to type a few letters in the location bar and history and suggestions would appear. Now I have to type in every web address I want to go to -- I don't know why the predictive typing and suggestions suddenly stopped working -- I haven't changed any settings. I've checked on Preferences/Privacy and it is set to Remember History and to suggest History and Bookmarks. I saw a similar question on here that suggested looking at the AVG add-on, but I don't have that. The predictive typing was very helpful -- I wish it hadn't disappeared!!! Can you please help?

    please tell me how to turn predictive text back on

  • Predictive typing problem in ios 8.1.3

    I think predictive typing is not good after updating ios 8.1.3. What's happening ? I turned on and off again and again, but still the same. Why?

    I wan downgrade iPhone 4s, ios8.1.2 to iOS 6.1.3 please...
    iOS 7&8 Is slowly on Iphone4 &4S, Open Downgrade please...

  • Predictive typing program for the Mac?

    Has anyone heard of a predictive typing program for the Mac?
    I am looking for a computer program for typing that "guesses" what word you want based on the first few letters. I have trouble typing because of physical disabilities. Voice recognition is a no go (I also have trouble with my voice).
    I know cell phones have this for texting, but I've never seen it for a regular computer. An application I could type in right on my Mac, then cut and paste to other applications like Word, email, etc. Apparently there is a program called "Penfriend" for the PC that does exactly this, but I'm having trouble finding anything Mac-compatible.
    Has anyone heard of a company that provides this kind of software? Any ideas on which discussion board might know?
    I have a 2006 Macbook Pro.
    Grateful for any help!
    2006 Macbook Pro   Mac OS X (10.4.3)  
    2006 Powerbook G5   Mac OS X (10.4.3)  
      Mac OS X (10.4.3)  

    Sorry for the delay, I was waiting for a "good arm" day to start typing!
    Were you using the mouse to select words? You can set
    hotkeys so you can do it with the keyboard if that
    would be easier - you can use a sequence like
    option-1,option-2, etc., or whatever else you can
    type easily.
    I tried both selecting words with the mouse, and with the coded numbers on the keyboard... I think this may be a problem for me with any predictive typing program, the whole needing-to-pick-up-your-hand thing. KeyStrokes seems about as good as you're going to get (honestly, all those languages, like magic). Maybe with a different keyboard, if I can place the numbers closer to the letters. I'll keep trying.
    There's no users group that I know about. I keep
    meaning to start a Yahoo list for OS X users who use
    assistive tech, but I have so many things that I want
    to do *wry grin* Maybe one day...
    That's a great idea -- I know there must be something out there, but I've mostly found disease-specific boards (ALS, etc.).
    2006 Powerbook G5   Mac OS X (10.4.3)  

  • Slow predictive typing in Address Book

    When I type a name in the search window of Address Book, the letters are very slow to appear and the find is delayed; however, if a name is pasted in the find is very fast.
    When left deleting letters in a name the deletion slows down, especially when approaching the first two or three letters, but when the whole name is selected and deleted there is no delay.
    This seems to be problem with predictive typing, if so, does anyone have an idea about how it might be cured?

    I'd start by doing a shift-login; i.e., hold down the shift key just after you enter your login password and keep holding it until the desktop appears. That prevents your login items from loading.
    Then try moving your AB database in
    Library/Application Support/AddressBook
    out of the way and creating a new one. If that isn't it, try the preference files,
    Library/Preferences/com.apple.AddressBook.abd.plist Library/Preferences/com.apple.AddressBook.plist
    Then there are various cache files you can delete.

  • Predictive Typing

    Does predictive typing support more than one language? Can you write one message in Spanish, the next in English?

    Does predictive typing support more than one
    language? Can you write one message in Spanish, the
    next in English?
    Input and user interface are English only in this version. Spanish display should work fine.
    http://m10lmac.blogspot.com/2007/06/iphone-language-capabilities-seem.html

  • My predictive typing in iOS 8 stopped working

    It was there and I liked it.  Now it is gone and I don't.  I don't see anywhere in Settings that I can opt out of it accidentally. Tried turning phone off and back on. No luck.  Any suggestions? 

    Really, Apple? I had the "predictive" toggle switched on, but the feature did not work until I did what was suggested by neokrelic. Mind you, it worked fine at first, but once I rest all settings (a remedy for another iOS 8 ailment, suggested by an Apple "genius") it stopped working. I was stumped! Perhaps it's time Apple put together a darn user manual for iOS?

  • How to stop typing on JTextField at...

    Hello, I have JTextField and want to limit inputting after
    certain number of text. Say, I want to limit after
    10 characters are inputted. How to do this?
    I try setColumns method but does not give the effect
    I want.
    Anybody knows please post!
    Thanks,
    Ted.

    Here's an simple and easy solution using PlainDocument. It gives a beep sound if the user tries to enter text after the specified length.
    textField.setDocuemnt( new TextFieldVerifier() );
    class TextFieldVerifier extends PlainDocument {
    int requiredLength = 10; // whatever length you want
    public void insertString( int offset, String str, AttributeSet attSet ) throws BadLocationException {
    boolean valid = true;
    if (str == null) {
    return;
    String old = getText( 0, getLength() );
    /* insert the new string at the given offset, into the old string */
    String newStr = old.substring( 0, offset ) + str + old.substring( offset );
    if (newStr.length() > requiredLength)
    valid = false;
    Toolkit.getDefaultToolkit().beep();
    if ( valid )
    super.insertString( offset, str, attSet );
    }

  • Address book predictive typing is...um..."slow"?

    Is there a way to edit the addresses that Mail has memorized, and possibly delete or at least re-prioritize them? Example: There are several people named "Phil" in my address book, and probably the last 30 times I've typed it I meant my father. But every single time the default suggestion is a former colleague of mine from a job 3 years ago.
    Does Mail make any attempt to guess the most likely match? How does it decide which one to suggest? Can I tell it to do something different?

    you can delete obsolete emails from the previous recipients list. it's available in mail from window menu->previous recipients. but that will only get rid of emails that are not in your address book. there is nothing you can do to tell Mail to offer one email before another one.

  • Assign integer to value typed in jtextfield

    Hello I am having trouble with basics.
    i have a jtext field private JTextField  theAmountOfStock   = new JTextField();and later on an integer which is assigned a value of 1 int    amount = "1";I don't want the integer to be 1 I want it to be what ever the user types in to the jtextfield, could anyone give me advice on how to do this? help much appreciated.

    thanks for not being patronising, i hav only just
    started learning java. Therefore i'm still not
    understanding (please forgive my incompetence)Important skills you have to master:
    - break up a problem into steps. You don't want to assign an int from a text field. You want to get the field's contents, and you want to change a String into an int.
    - Read the API. I didn't use proper capitalization - look at the Integer class
    - Use the search. There must be thousands of posts that explain how to convert a String to an int. I think I posted one before, today.
    I apologize for sighing, it was mostly related to part 2 and using a text area without knowing how to get its contents. The API should be the first thing to refer to before using a class.

  • Address book-predictive typing?

    The old address book versions would predict the entries; city or state or names. The OS 10 version doesn't seem to do a whole lot. Am I missing some preference settings?

    Actually, Address Book has an interesting bug. In the Edit it mode, deleted lines will reappear if clicking to different app. All the previous editing is lost and must be redone.
    Not a lot of effort was put into this system app.

  • Can predictive typing be turned off?

    as subject says.. did I miss a page on the manual?
    thanks

    Frankly, I'm not sure I understand why you'd want to turn it off, and I ALWAYS turn off the autocorrect features of any word processor I use. But I found the iphone does such a great job of learning that sometimes I'm in the middle of typing and I see I've made an error but I'm confident that if I just continue it'll get corrected -- and most of the time it does. How long have you had your iphone? I ask only because at first it really had to be taught, but with patience, it really has learned quite well and it usually guesses what I'm trying to type.
    Just to be sure, are you tapping the incorrect guesses, so that the phone learns that they're no good? If you just let it correct and then delete then you're not teaching it at all. I've found that only one or two taps on the same wrong suggestion is enough to have it not be suggested any more, instead it suggests what I ended up actually typing. That's what I mean by learning. Forgive me if you're already doing this but are not getting good results.

  • JTextField in JTableHeader

    Hello,
    I am trying to create table with filterbar. I am using my own reneder/editor for the table header which consist of JButton and JTextField on JPanel. After a character is typed to JTextField the table model is filtered and fireTableDataChanged is called. It works fine, but the JTextField loses focus and JTable gains it. I tried to request for focus again when JTable gains it, but it has no effect. Can you help me what should I do? Thank you!

    I tried to request for focus again when JTable gains it, but it has no effectWhen you use the fireTableDataChanged() method the TableColumnMode and TableHeader is recreated. So even though you request focus on your text field this code may be executed before the table header has actually been recreated.
    You can try wrapping the textField.requestFocusInWindow() method in a SwingUtilities.invokeLater() method. This will cause the request to be added to the end of the Event Thread, hopefully after the table has been recreated.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html]How to Use Threads for more information on invokeLater.

  • Typing SMS - autocorrection in nearly 80% wrong

    Hi,
    is there a possibility to disable the autocorrection. Now 2.1 is released and the autocorrection function is handled the same as before. This is ********, because I want an option to disable it, and to activly select a suggestion and not how the Iphone handles it, a suggestion which I must deselect.
    Nearly all books and literature about how to design intuitive ui-interfaces says that such a functionalitity must be opt-in. So why Apple (which did a great job in designing ui-interface in the past) isn't able to implement the autocorrection in a way a user can use it?
    I don't want to jailbreak my phone but at the moment it is the only way to disable the crappy autocorrection .
    Cheers,
    Michael

    "Auto-correction is the most moronic "feature" of the iPhone."
    It's funny that you should say that because I find it one of the smartest features! I know people who fight it as they type a word, expecting the correct 'option' to be available to them from the third (or second) letter onwards in 100% of cases and the instant they see the offered word is not the one they want (even though they haven't finished entering the complete word themselves) they panic and start correcting it themselves.......but the people I know (and myself) who carry on entering a word until they see the correct and complete option appear magically all love it! It's great too because very often if you accidentally touch an incorrect character on the keyboard and trust the auto-correction, then before you get to the end of the word the correct corrected option appears anyway! How smart is that?!!
    Yes, to make the most of this facility it is necessary to trust it more than people tend to do with 'conventional' predictive typing and not to panic +as soon as+ an incorrect character is entered or an inappropriate option is offered, but trusting it more I find now that I have to enter fewer actual characters to type almost anything completely correctly than on any other device (especially mobile) that I have ever known!
    I love it!!

Maybe you are looking for

  • Beaten Man on Jump Indirect

    I'm trying to return from stories and tracks to the last button selected on the calling menu using Jump Indirect. I swannee I read somewhere this scheme worked (and it does in Simulator). This works fine in the Simulator, but not always in DVD Player

  • Workflow bus0035

    I wanna use workflow to create notifications using BUS0035(REGARDING FUNDS AND GRANTS) CAN ANYONE EXPLAIN IT THANKS IN ADVANCE.

  • How to view local videos on iOS mobile device

    How do I view local videos on my iOS device running an Adobe Air app? I know how to view the CameraRoll for iOS in Flex on Adobe Air, but the CameraRoll class only brings up photos, no videos.  When I use: if (CameraRoll.supportsBrowseForImage) {    

  • DFU Mode and iTunes does not Restore only Update

    So we terminated one of our employees and he put a lock on the company issued phone.  I've put the phone in DFU Mode so I can just restore it through iTunes but iTunes keeps trying to Update before the restore then saying it cannot because the device

  • Reset ACS database password

    Hi, Just asking if you guys have idea how to reset the ACS database password? regards,