let me if have you anyone answer, this ans. basically required like as google search engine , when we press any key then it would be display suggestion related pressed key.
regard Satish Dhiman
let me if have you anyone answer, this ans. basically required like as google search engine , when we press any key then it would be display suggestion related pressed key.
regard Satish Dhiman
I can propose my own implementation. It is based on JList shown in JWindow. As I wanted to use this code for a combo box, I've disabled UP and DOWN keys with keyEvent.consume() call.
From my comment/previous code see this update:
Using
JTextField
withAutoSuggestor
:Using
JTextArea
(or any other JTextComponent besides JTextField will result in Pop up window being shown under caret) withAutoSuggestor
:As you can see I changed the code by making its constructor accept a
JTextComponent
rather than aJTextField
orJTextArea
etc.The problem we are left with is we have to show the pop up
JWindow
at a different position depending on theJTextComponent
passed i.e aJTextField
will have autosuggest window pop up at the bottom whileJTextArea
/JEditorPane
etc would have theJWindow
pop up under the caret/word.Have a look at this specific method
showPopUpWindow()
inAutoSuggestor
class:As you can see we check to see what instance the
JTextComponent
is and if its not aJTextField
simply get the caret position (via theRectangle
of the caret) of theJTextComponent
and positionJWindow
pop up from there (underneath the caret in my case).