可编辑的JCombobox和关键监听器

时间:2023-01-28 07:35:51

how to add key event listener in jcombobox so that it accepts the whole String for ex. if i add 'S' it should search for the String that start with 's' in database .if there are no result then it should wait for the user to type other character in the combobox to get the similar results

如何在jcombobox中添加键事件侦听器,以便它接受ex的整个String。如果我添加'S',它应该搜索在数据库中以's'开头的字符串。如果没有结果那么它应该等待用户在组合框中键入其他字符以获得类似的结果

2 个解决方案

#1


1  

Check if this helps-

检查这是否有帮助 -

    comboBox.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent ke) {
            // get the text typed and search for it
            // get the text from combo box, and not from the key event
        }
    });

#2


1  

You have an option of either implementing it yourself or you can use Java2sAutoTextField or Java2sAutoComboBox. Both of them are easy to use.
You simply supply a java.util.List<> that contains data pulled from your database and that would do the task of auto completing for you.
To get a better idea, look at my question here: Implementing auto complete in Java - am I doing it right?

您可以选择自己实现它,也可以使用Java2sAutoTextField或Java2sAutoComboBox。它们都很容易使用。您只需提供一个java.util.List <>,其中包含从您的数据库中提取的数据,并为您执行自动完成的任务。为了获得更好的想法,请在这里查看我的问题:在Java中实现自动完成 - 我做得对吗?

You also have another option of using GlazedLists
I believe I have adequately answered your question :)

您还有另一种使用GlazedLists的选择我相信我已经充分回答了您的问题:)

#1


1  

Check if this helps-

检查这是否有帮助 -

    comboBox.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent ke) {
            // get the text typed and search for it
            // get the text from combo box, and not from the key event
        }
    });

#2


1  

You have an option of either implementing it yourself or you can use Java2sAutoTextField or Java2sAutoComboBox. Both of them are easy to use.
You simply supply a java.util.List<> that contains data pulled from your database and that would do the task of auto completing for you.
To get a better idea, look at my question here: Implementing auto complete in Java - am I doing it right?

您可以选择自己实现它,也可以使用Java2sAutoTextField或Java2sAutoComboBox。它们都很容易使用。您只需提供一个java.util.List <>,其中包含从您的数据库中提取的数据,并为您执行自动完成的任务。为了获得更好的想法,请在这里查看我的问题:在Java中实现自动完成 - 我做得对吗?

You also have another option of using GlazedLists
I believe I have adequately answered your question :)

您还有另一种使用GlazedLists的选择我相信我已经充分回答了您的问题:)