当前位置: 技术问答>java相关
请问Swing中的JTree控件如何让监听一个子叶的鼠标事件?
来源: 互联网 发布时间:2015-01-19
本文导语: | import ......; final JTree tree = new JTree(); MouseListener ml = new MouseAdapter() { public void mouseClicked(MouseEvent event) { int selRow = tree.getRowForLocation(event.getX(), event.getY()); Tree...
|
import ......;
final JTree tree = new JTree();
MouseListener ml = new MouseAdapter()
{
public void mouseClicked(MouseEvent event)
{
int selRow = tree.getRowForLocation(event.getX(), event.getY());
TreePath selPath = tree.getPathForLocation(event.getX(), event.getY());
if(selRow != -1)
{
DefaultMuteNode node = (DefaultMuteNode)tree.getLastSelectedPathComponent();
if (node.isLeaf())
{
//event deal operation.
}
}
}// of public void mousePressed(MouseEvent event)
}; // mouseListener defined
tree.addMouseListener(ml);
final JTree tree = new JTree();
MouseListener ml = new MouseAdapter()
{
public void mouseClicked(MouseEvent event)
{
int selRow = tree.getRowForLocation(event.getX(), event.getY());
TreePath selPath = tree.getPathForLocation(event.getX(), event.getY());
if(selRow != -1)
{
DefaultMuteNode node = (DefaultMuteNode)tree.getLastSelectedPathComponent();
if (node.isLeaf())
{
//event deal operation.
}
}
}// of public void mousePressed(MouseEvent event)
}; // mouseListener defined
tree.addMouseListener(ml);