AutoCompleteSupport and listening for enter key...

View: New views
2 Messages — Rating Filter:   Alert me  

AutoCompleteSupport and listening for enter key...

by Niklas K. Rasmussen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What is the correct way to listen for the enter key in AutoComplete
JComboBox?

I want to save the entered string, when the user press enter...

my code:

JComboBox jComboBox = new JComboBox();
EventList<String> eventList = new BasicEventList<String>();
AutoCompleteSupport support = AutoCompleteSupport.install(jComboBox,
eventList);


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Parent Message unknown Re: AutoCompleteSupport and listening for enter key...

by Holger Brands :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here is one way that should work (hopefully):

JComboBox jComboBox = new JComboBox();
EventList<String> eventList = new BasicEventList<String>();
AutoCompleteSupport support = AutoCompleteSupport.install(jComboBox, eventList);
jComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            System.out.println(((JTextField) jComboBox.getEditor().getEditorComponent()).getText());
        }
    }
});

Hope this helps,
Holger

> What is the correct way to listen for the enter key in AutoComplete
> JComboBox?
>
> I want to save the entered string, when the user press enter...
>
> my code:
>
> JComboBox jComboBox = new JComboBox();
> EventList<String> eventList = new BasicEventList<String>();
> AutoCompleteSupport support = AutoCompleteSupport.install(jComboBox,
> eventList);
>

________________________________________________________________
Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...