This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to get the bounds of a node in JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get the bounds of a node in JTree" Watch "How to get the bounds of a node in JTree" New topic
Author

How to get the bounds of a node in JTree

Nagarajan Thangapandi
Greenhorn

Joined: Mar 18, 2008
Posts: 9
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

Joined: Jul 26, 2007
Posts: 10274
    
    8

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.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Check out the JTree API. There are two methods that return a Rectangle; both start with "get" and end with "Bounds()".


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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!


True person is moral, false is right!
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

This link tells how to get coordinates of node in jtree
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the bounds of a node in JTree