Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想搜索 JTree 的特定节点并确定它在屏幕上的位置。我的目标是从该节点的左上角开始悬停鼠标并在我的 JFC 中执行鼠标单击。
谁能帮我这个?是否可以?
知道坐标 x 和 y(来自鼠标事件),您可以通过JTree.getPathForLocation. 节点的边界由JTree.getPathBounds(path).
JTree.getPathForLocation
JTree.getPathBounds(path)
在不了解更多信息的情况下,很难确定这一点。
不过,我建议你看看
这应该可以帮助您确定节点在屏幕上的位置
您可以使用 processMouseEvent。MouseEvent 将为您提供鼠标的 X 和 Y 坐标。