从JLabel删除MouseListener() [英] Removing MouseListener() from a JLabel
本文介绍了从JLabel删除MouseListener()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JLabel
上添加了MouseListener
.现在,如果我想禁用与JLabel
关联的MouseListener
,当单击标签一次时,该怎么做.
I added a MouseListener
to a JLabel
. Now if I want to disable this MouseListener
associated with the JLabel
, when the label is clicked once, how can I do it.
我知道单击标签时有一个很大的方法来设置布尔值或int变量,然后调用方法并在那里删除MouseListener
,但是我想学习一种紧凑而简单的方法.有办法吗?
I know there is a big way to set a boolean or int variable when the label is clicked and then call a method and remove MouseListener
there, but I want to learn a compact and easy way. Is there a way to do this?
推荐答案
在鼠标侦听器中:
public void mouseClicked(MouseEvent event) {
// Do stuff...
((Component) event.getSource()).removeMouseListener(this);
}
这篇关于从JLabel删除MouseListener()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文