문제

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