3

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?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
DarkKnight
  • 243
  • 1
  • 4
  • 10

3 Answers3

6

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

Ingo Kegel
  • 46,523
  • 10
  • 71
  • 102
  • This gives the location of x and y of origin. How to get the location of rightmost x and y? – DarkKnight Aug 29 '12 at 21:37
  • 1
    @DarkKnight `getPathBounds` returns a `Rectangle`. The right most x position is `bounds.x + bounds.width` and the right most y position is `bounds.x + bounds.height` – MadProgrammer Aug 29 '12 at 23:28
2

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

However, I'd suggest you take a look at

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

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

You can use processMouseEvent. And the MouseEvent will get you the X and Y coordinates of your mouse.

dan
  • 13,132
  • 3
  • 38
  • 49