Search code examples
javaswingmouseeventjtreeswingutilities

How to find location of JTree node on screen


I want to search a particular node of JTree and determine its location on screen. My aim is to start hovering mouse from the top left corner of that node and perform a mouse click in my JFC.

Can anyone help me with this? Is it possible?


Solution

  • Knowing the coordinates x and y (from the mouse event), you can get the path via JTree.getPathForLocation. The bounds of the node are returned by JTree.getPathBounds(path).