Вопрос

I'm using a JComboBox to search a query from a sql DB. I want to search query when a letter is typed. I'm using net beans IDE. Here is the automated code.

srch.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            srchKeyReleased(evt);
       }
}

private void srchKeyReleased(java.awt.event.KeyEvent evt) {
    //Searching code
}

But nothing happens. I'm sue that there is no error in searching code. Please give me the code to do this without automated code from IDE. name of JComboBox is srch . Combo box editable=true. Thank you.

Это было полезно?

Решение

Since your combobox is editable, you should try this:

srch.getEditor().getEditorComponent().addKeyListener()

instead of this

srch.addKeyListener()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top