日期:2014-05-20  浏览次数:20635 次

swing小问题,求大侠们帮忙
我想移除对一个表格的鼠标监听
table.removeMouseListener(null);
这样写对吗?不好用啊!!!


------解决方案--------------------
探讨

引用:
listener s;

table.addMouseListener(s);
table.removeMouseListener(s);

Java code

table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEve……

------解决方案--------------------
禁止
Java code
table.addMouseListener(new MouseListener(){
    public void mousePressed(MouseEvent e){
        e.consume(); // 将鼠标事件消费掉
    }
    // 其他方法类似
});

------解决方案--------------------
探讨

引用:
listener s;

table.addMouseListener(s);
table.removeMouseListener(s);

Java code

table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEve……

------解决方案--------------------
// 添加一个监听器,并为之赋值
MouseAdapter ma = null;
this.addMouseListener(ma = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println("sdfsd");
};
});
//将其删除
this.removeMouseListener(ma);