Java MouseListener for ComboBox

好久不见. 提交于 2019-12-13 06:58:01

问题


How do I add a MouseListener to a ComboBox? I have tried:

comboBox.addMouseListener(new MouseAdapter() { 
    public void mousePressed(MouseEvent event) {
        System.out.println("ok");   
    }

    public void mouseReleased(MouseEvent event) {
        System.out.println("ok");   
    }
});

It doesn't seems to work. I need to make the program do something when I press on the ComboBox, for example for typing because it is editable.


回答1:


For basic swing related questions (I assume you use swing here), check the swing trail of the Java tutorial.



来源:https://stackoverflow.com/questions/6827784/java-mouselistener-for-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!