我正在编写一个 MouseListener
来替换 JTree
中的默认单击行为。我如何知道何时单击此图标,以便我可以自己展开该行? (我知道这是默认行为,但我正在用我自己的 MouseListener
替换默认的 MouseListener
)。
这是我的代码:
// Custom mouse listener for the tree
MouseListener treeMouseListener = new MouseAdapter()
{
public void mousePressed (MouseEvent e)
{
TreePath path = cameraTree.getPathForLocation(e.getX(), e.getY());
// Do some methods based on what was clicked
...
}
};
单击 +/- 图标时,cameraTree.getPathForLocation(e.getX(), e.getY())
返回的 TreePath 为 null。我如何知道 +/- 图标何时被单击?
最佳答案
如果您使用 JTree,则可以使用 TreeSelectionListener。 更多信息请点击:http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html
关于java - 检测何时在 JTree 中单击展开/折叠(加号/减号)图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22611739/