Looking for how to traverse a JTree (can do that) and check to see each node to see if it’s displayed (to the user) or not visible. Can’t believe JTree doesn’t have this function, maybe I’m missing something?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You must consider two different things:
A node can become hidden by closing one of its parents. Even though the parent is visible on the screen, the child isn’t. Use JTree.isVisible() for this.
If the node is expanded, it can become hidden because it is scrolled out of the current viewport. This isn’t handled in the JTree but in the JScrollPane which wraps the tree. To find out if a node is in the visible area of the viewport.
To find out if #2 is true, you must get the rectangle where the node is using JTree.getPathBounds(). Then, you must intersect this rectangle with the viewport (use
scrollPane.getViewport().getViewRect(). IfnodeRect.intersects (viewRect)returnstrue, the node is visible.