Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a Swing to read input without a submit button

Tags:

java

submit

swing

This is for an assignment so responses should not contain the code written for me.

I have written a program that is essentially an auto-complete program. It takes a word and returns the best matches.

I am trying to write a front end for it in swing(which I have no experience in) and want my front end to do the following: I want the input box to constantly be reading for user input, feeding that value to the other program, and returning the matches immediately in a drop down box, as, say, Google does. I can't seem to find any information on how to do this, all the intro tutorials use a submit button.

Can anyone explain to me how this would be done, or point me to a resource that could explain it? Again, please don't write the code for me, I don't want to unwittingly cheat on my assignment.

like image 559
DazedAndConfused Avatar asked Dec 21 '22 01:12

DazedAndConfused


2 Answers

If you are using a JTextField, you could register a document listener on it.

like image 190
VirtualTroll Avatar answered Dec 23 '22 15:12

VirtualTroll


If your input box is a JTextField, you can add a DocumentListener (this is a good tutorial) to capture character entries.

like image 42
assylias Avatar answered Dec 23 '22 15:12

assylias