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