Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the bounds of a node in JTree

 
Nagarajan Thangapandi
Greenhorn
Posts: 9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to get bounds of a node in the JTree. Can some one tell me how to get that.

Thanks in advance.
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagarajan,
Welcome to the Ranch.

The DefaultMutableTreeNode i.e. the "node" represents the data. What you see on the screen, will be the renderer.
Once you identified your node, you will have to figure out the corresponding renderer and then get it's bounds.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the JTree API. There are two methods that return a Rectangle; both start with "get" and end with "Bounds()".
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

@Manesh, please tell how to figure out corresponding renderer for my current node.
My node is DefaultMutableTreeNode and it has no method to get either its renderer or its bounds.
DefaultTreeCellRenderer has method getBounds but this method does not anyhow refer to certain node.

Thanks!
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link tells how to get coordinates of node in jtree
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic