Java Editable JCombobox Keylistener event for Enter key

前端 未结 6 1836
太阳男子
太阳男子 2020-12-11 05:56

I have editable JCombobox and I added keylistener for combobox editor component. When user press \'Enter key\' and if there is no text on the editable combobox I need to dis

6条回答
  •  孤街浪徒
    2020-12-11 06:43

    If you are using Netbeans then right click on your combobox and select customize code. add following lines of code

    JTextComponent editor = (JTextComponent) Code.getEditor().getEditorComponent();
    editor.addKeyListener(new KeyAdapter() {
       public void keyReleased(KeyEvent evt) {
            if(evt.getKeyCode()==10)
                //do your coding here.
       }
    });
    

提交回复
热议问题