Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 286
DarkKnight Avatar asked Dec 11 '25 17:12

DarkKnight


2 Answers

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).

like image 157
Ingo Kegel Avatar answered Dec 14 '25 05:12

Ingo Kegel


Without knowing more information, it's hard to nail this down.

However, I'd suggest you take a look at

  • JTree.getPathBounds
  • JTree.getRowBounds
  • JTree.getRowForPath
  • SwingUtilities.convertPointToScreen

This should help you work out where on the screen a node is

like image 41
MadProgrammer Avatar answered Dec 14 '25 07:12

MadProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!