为树中的节点添加操作侦听器
我无法将操作侦听器添加到树中的特定节点。这是我构建的树:
我想为每个节点注册一个单独的侦听器。现在我已经在JTree
上注册了一个监听器。因此,每当我单击树的任何部分时,侦听器方法就会开始工作。 (即现在我有一个共同的听众) 我想要的是,当我点击音频时,注册为听到音频点击的侦听器应该开始工作,视频也是如此。 我该怎么做?
这就是我到目前为止注册的方式:
jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
jTree1ValueChanged(evt);
}
});
public void jTree1ValueChanged( TreeSelectionEvent tse ) {...}
I am unable to add action listener to a particular node in the tree. This is a tree that i've constructed :
I want to register a separate listener for each node . Now i have registered a listener on JTree
. so, whenever i click on any portion of tree
the listener method starts it's work. (i.e now i have a common listener )
What i want is when i click on audio a listener registered to hear audio click, should start it's work and the same goes for video. How can i do that ?
This is how i have registered so far :
jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
jTree1ValueChanged(evt);
}
});
public void jTree1ValueChanged( TreeSelectionEvent tse ) {...}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这又怎样呢。或者你有特殊的 PathComponents 吗?
What about this. Or do you have special PathComponents?
您无法向树节点添加事件侦听器,因为表示树节点的类不是组件。
You cannot add an event listener to tree-node because the class representing the tree-node is not a Component.