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?

1
  • What do you mean by finding a node on screen?
    – Dan D.
    Aug 29, 2012 at 20:42

3 Answers 3

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

2
  • This gives the location of x and y of origin. How to get the location of rightmost x and y?
    – DarkKnight
    Aug 29, 2012 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 Aug 29, 2012 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

1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.