Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6347421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:12:38+00:00 2026-05-24T21:12:38+00:00

I have a JTree on a JScrollPane as part of my GUI. I’ve set

  • 0

I have a JTree on a JScrollPane as part of my GUI. I’ve set up an AncestorListener where I respond to the ancestorAdded event. In the event, I would like to automatically expand as many visible nodes as possible. By visible, I mean that I want to expand as many nodes as possible such that the total height of the tree does not exceed the maximum height of the JScrollPane’s viewport. If my viewport had 500px of visible space, I want the tree expanded until the total expanded height is less than or equal to 500px.

I’ve tried to achieve this a few different ways. It boils down to this: I can’t seem to retrieve an updated height for the tree after programatically expanding a node. How can I recalculate the height of the tree? tree.getHeight(), for example, always returns the same value even after I expand a node. Invoking tree.invalidate() between calculations didn’t help either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:12:39+00:00Added an answer on May 24, 2026 at 9:12 pm

    How can I recalculate the height of the tree?

    Maybe getVisibleRowCount()*getRowHeight() will give you the correct size.

    The documentation for getRowHeight() states that it may return <= 0 and leave the row height up to the renderer, which may be the case for you as you’re using a JTreeTable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JScrollPane which contains only one instance of JTree. How can I set
I would like to have a JTree which also displays some extra information right
I have a simple Jython GUI that displays an XML file in a JTree.
I would like to have the editor in my editable JTables select all text
I have a large JTree and I need to expand thousands of nodes all
I would like to have a way to display the contents of an XML
I have a JTree, a JTable and a JList which displays the same set
I have a JTree populated with some (custom) nodes. I have a class that's
I have a JTree which contains file/directory, i want to get a list which
i have a JTree in Java with different parent nodes such as computers, gaming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.