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

  • Home
  • SEARCH
  • 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 271053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:06:03+00:00 2026-05-12T00:06:03+00:00

This method works as expected – it creates a JTree with a root node

  • 0

This method works as expected – it creates a JTree with a root node and two child container nodes (each with a respective leaf node):

private JComponent createSideBar()
{
    final DefaultMutableTreeNode top = new DefaultMutableTreeNode("Projects");
    final JTree tree = new JTree(top);

    DefaultMutableTreeNode project = new DefaultMutableTreeNode("project 1");
    DefaultMutableTreeNode version = new DefaultMutableTreeNode("version 1");
    project.add(version);
    top.add(project);
    TreePath treePath = new TreePath(project.getPath());
    // tree.expandPath(treePath);

    project = new DefaultMutableTreeNode("project 2");
    version = new DefaultMutableTreeNode("version 2");
    project.add(version);
    top.add(project);

    return tree;
}

In this case, the tree starts out closed. I’d like the application to start with all nodes fully expanded so I started by adding the following:

    tree.expandPath(treePath);

but when I un-comment it from the code above, the second set of child nodes don’t show up, ie: Project 2 and Version 2 do not show up. In fact, all subsequently added nodes never show up.

For what its worth, I’m using JDK 1.5. From the docs, I can’t seem to see any restrictions or why this method would have such ill-effects … I’m going to try to look at the source but was hoping someone might have a good idea what and why this is expected behavior. I’m wondering if each subsequent node ‘add’ is somehow disallowed somehow – but I can’t imagine would work for most run-time use cases.

Thanks,

-Luther

  • 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-12T00:06:04+00:00Added an answer on May 12, 2026 at 12:06 am

    Unfortunately, Swing is often “helpful”. In this case, it is creating a model for you from the data supplied, much the same as a JList would create a model if you supplied a Vector.

    JTree and accomplices (primarily the Pluggable Look & Feel) will add listeners to the model to keep informed of updates. If you just change the data behind the (implicit) model’s back, nothing will get updated other than by chance.

    So, what you should do is explicitly create a model. When the model data changes (always on the EDT, of course), cause the relevant event to be fired.

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

Sidebar

Ask A Question

Stats

  • Questions 189k
  • Answers 189k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is that, I misspelled the class name so… May 12, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer Yes. The thread shall be suspended for that cycle allowing… May 12, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer Yep, you'll want to look at the PVRTextureLoader sample. It's… May 12, 2026 at 5:42 pm

Related Questions

This method works as expected - it creates a JTree with a root node
Can I safely use DateTime as a key in a SortedDictionary<K, V> without implementing
I am using Jython 2.2.1 and MySQL Connector/J 5.1 to access a MySQL database.
I have a bizarre problem that is doing my head in. I have the
I'm almost there understanding simple reference counting / memory management in Objective-C, however I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.