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 6905151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:08:56+00:00 2026-05-27T08:08:56+00:00

Basically I edit an attribute private string status=OK in the UserObject() of a DefaultTreeNode()

  • 0

Basically I edit an attribute private string status="OK" in the UserObject() of a DefaultTreeNode().

I have a CustomRenderer which implements DefaultCellRenderer, which sets the Icon by rendering the “OK” attribute of UserObject of a TreeNode.

Originally, when I select a node, the icon changes. I am using Tree.revalidate() & Tree.repaint(), and the change is being reflected.

However, I am not sure if this very efficient. What would be the proper way of doing this? I tried doing TreeModel.nodesChanged(new DefaultMutableTreeNode(myUserObject)) but the TreeNodeChanged event will not fire.

So am I stuck to using repainting the entire tree everytime a userboject of a TreeNode is changed to see the graphic update?

  • 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-27T08:08:56+00:00Added an answer on May 27, 2026 at 8:08 am

    Use the approach shown in TreeIconDemo2 to condition the renderer based on the model’s value. For example,

    private class MyRenderer extends DefaultTreeCellRenderer {
    
        private Icon okIcon;
    
        public MyRenderer(Icon okIcon) {
            this.okIcon = okIcon;
        }
    
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value,
            boolean sel, boolean exp, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(
                tree, value, sel, exp, leaf, row, hasFocus);
            YourMutableTreeNode node = (YourMutableTreeNode) value;
            if (leaf && node.getStatus().equals("OK")) {
                setIcon(okIcon);
            }
            return this;
        }
    }
    

    Addendum: You can’t simply invoke nodeChanged() on a new TreeNode that’s not part of the tree; the new node has no parent. If you specify an existing node to nodeChanged(), the notification will happen automatically. If needed, there’s an example of searching a tree here.

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

Sidebar

Related Questions

I have a relatively big SSIS package which I'm trying to edit. I basically
I'm trying to load a page that is basically an edit form inside a
EDIT: I am basically running into the following documented issue . I am using
Basically I have some code to check a specific directory to see if an
Having a bit of a special moment here. Basically I have a DB table
Similar question from last night, I don't have access to edit the source HTML
I have an onclick function which performs several tasks. In another JavaScript function I
i'm trying to make my own IAuthorizationFilter attribute class. Basically, each api call has
Basically, I have 4 levels of nested forms. A has B has C has
Basically i want to create XMLDesigner kind of thing in Flex, using which user

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.