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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:34:36+00:00 2026-05-18T22:34:36+00:00

I have the following problem (this is related to my post blink a tree

  • 0

I have the following problem (this is related to my post blink a tree node):
I have a custom cell renderer.
In some part of my code I create a new DefaultMutableTreeNode and store it in a list

public static List<DefaultMutableTreeNode> nodes = new ArrayList<DefaultMutableTreeNode>() 
//in some time
DefaultMutableTreeNode aNode = new DefaultMutableTreeNode("SomeValue");
nodes.add(node);

In my cell renderer I do:

public Component getTreeCellRendererComponent(JTree tree, Object value,
      boolean selected, boolean expanded, boolean leaf, int row,
      boolean hasFocus) {
    DefaultMutableTreeNode n = (DefaultMutableTreeNode)value;
    if(nodes.contains(n)){
     //set background to red
    }
}

At this point nodes has a node but the code never goes in the if branch.
Why? I can not understand since I already stored it in the arraylist. Do I get a different reference?
Also I created a swing timer:

Timer t = new Timer(400, new ActionListener(){
   public void actionPerformed(ActionEvent evt) {
        if(nodes.size == 0)
            return;
        TreePath p = new TreePath(nodes.get(0));
        Rectangle r = tree.getPathBounds(p);
        tree.repaint(r);
   }

});    

But I get a NPE in tree.getPathBounds.
I can not understand why. Can’t I manipulate DefaultMutableNodes I stored in my list this way? What am I doing wrong in my thinking?
Note: If I simply call repaint(); in the timer and in the cell renderer I loop over the nodes to see if it displays the sametext with the node I have stored, what I want I get the blinking, works

Thanks

  • 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-18T22:34:37+00:00Added an answer on May 18, 2026 at 10:34 pm

    Actually TreePath is a list of objects… path from tree root to the node. If you create a path from the single node the path exists in the tree only if the node is root of the tree.
    I woul recommend to use TreeSelectionEvent public TreePath[] getPaths() method. The method provides actual paths.

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

Sidebar

Related Questions

This is a code review question more then anything. I have the following problem:
Never thought I'd have this problem :) The following snippet of code works in
I have been working on the following problem from this book . A certain
I have the following problem. I am making this website you can see in
Hello i have the following problem, I record a video using red5 like this:
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
Following up this question , I have a further problem - I have two
I have problems with the following bit of javascript/jquery code: this.droppable = function(){ $('.imageWindow
I have the following code as part of a jquery script to open a
I have tried solving this problem by posting other related questions here that focused

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.