树节点选择监听器
仅当之前未选择该节点时,nodeSelectListener 才会触发。如果已经选择了一个节点,并且我们再次按下同一节点,则不会调用侦听器。如何覆盖它,以便即使在同一节点上的每次单击都会触发 nodeSelectListener?
nodeSelectListener will only trigger if the node is previously not selected. If a node is already selected, and we press the same node again, the listener will not be called. how to overwrite this so that every single click even on the same node will fire nodeSelectListener?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法通过该特定侦听器来执行此操作,因为(根据设计)选择侦听器仅在先前未选择节点时才会触发。请参阅此错误报告以获取对此的讨论。您需要一个 onclick 处理程序。
You can't do it via that particular listener, because (by design) the select listener only fires when the node was not previously selected. See this bug report for a discussion of it. You want an onclick handler instead.
java 并不是我的强项,但也许您可以使 onclick 处理程序取消选择然后重新选择节点,而不是完全替换侦听器?
java isn't really my forte, but perhaps instead of replacing the listener altogether, you could make the onclick handler just deselect and then reselect the node?
在
nodeSelectListener
旁边使用MouseListener
怎么样?How about using
MouseListener
besidenodeSelectListener
?我真的不知道我在说什么......但这可能吗?
选择时,收集节点的大小和位置以及节点本身。然后单击时,通过查看当前位置是否在矩形内来查看是否位于同一节点上。请务必在必要时清除已保存的选择信息。
I really DON'T know what I'm talking about... but is this possible?
On select, collect the size and position of the node, along with the node itself. Then on click, see if you're on the same node by seeing if the current position is within the rectangle. Be sure to clear the saved selection info when necessary.