Although the above kind of works, it still has some problems. The first is that if I press a "backspace" character, it won't try to match any results. Also, if I highlight the whole text in the textfield and press a letter, it won't attempt to match either. The reason for the later is that the textfield at that time is not blank and so prefix becomes the textfield plus the newly entered letter, whereas it should be the newly entered letter.

The best way to do this is to use a DocumentListener instead of a KeyListener. When the DocumentEvent is fired the document has already been updated and you can just use getText() to get the contents of the Document. No need to play around with backspace characters.