1

I am developing a Swing application in which I need to refresh the tree periodically. Each node in the tree represents certain task that is run in an independent thread. Each node contains checkbox + status indicator of task that it executes (represented by JPanel). I've written a custom TreeCellRenderer in order to change components appearance. I am implementing the javax.swing.tree.TreeCellRenderer interface in my renderer and overridden the below method of it.

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)

I want to make this method to be invoked every 1 second so that it would refresh the status of the underlying task that each node executes.

Can someone please tell me how to invoke getTreeCellRendererComponent() every 1 second? Which event should be fired from a separate thread? I am currently achieving this by calling updateUI() method on the JPanel which contains JTree, but that blocks my whole UI until the call returns from getTreeCellRendererComponent().

[UPDATE]: I am using DefaultTreeSelectionModel and I don't want to update the JTree when a new node is added or removed, but to update the JTree when the task associated with each node finishes. The tasks are executed when I click Run button added in my UI. Once Run button is pressed I want to update each node with different color in the JPanel added to node.

ParagJ
  • 1,566
  • 10
  • 38
  • 56
  • Why not simply call [nodeChanged()](http://docs.oracle.com/javase/7/docs/api/javax/swing/tree/DefaultTreeModel.html#nodeChanged%28javax.swing.tree.TreeNode%29) every time you're notified by the background thread that a task status has changed? – JB Nizet Mar 27 '15 at 09:59

0 Answers0