문제

I have the following code to listen for mouseclicks, but it appears to not always fire.

nameList.addChangeListener( new MouseAdapter(){
    @Override
    public void mouseClicked(MouseEvent me) {
        nameListUpdated();
    }
} );

nameListUpdated() will run some of the times, but for whatever reason it seems that it will not run on every click like i want. Does anyone know why? Or is there more information to find the problem?

도움이 되었습니까?

해결책

I would suggest instead of using method addChangeListener

 nameList.addChangeListener( new MouseAdapter(){
 @Override
 public void mouseClicked(MouseEvent me) {
     nameListUpdated();
 }
} );

use method for adding mouse listener addMouseListener

 nameList.addMouseListener( new MouseAdapter(){
 @Override
 public void mouseClicked(MouseEvent me) {
     nameListUpdated();
 }
} );

다른 팁

Try using mousePressed instead. It will fire an event when you press mousebutton without waiting until you release it. In most cases it does the trick.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top