jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes A JTree with JProgressBar's for its nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A JTree with JProgressBar Watch "A JTree with JProgressBar New topic
Author

A JTree with JProgressBar's for its nodes

Paul Statham
Ranch Hand

Joined: Dec 05, 2008
Posts: 56
Hi Folks,

GUI code is not my forte as you'll probably be able to tell, essentially I want to have what I've described in the title. I came across this stackoverflow answer http://stackoverflow.com/questions/7036036/adding-multiple-jprogressbar-to-tablecolumn-of-jtable/7036206#7036206 which is specific to a JTable.

I have butchered this and spent quite some time trying to do essentially the same thing but with a JTree instead. The problem I have is the progress bars do not automatically refresh as they do the JTable example I found, instead they only refresh when they are clicked on, for the life of me I can't work out why? Also the second problem I have is that when I first expand my JTree, the expand icon disappears! Here's the code

Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

I didn't read most of your code, but what has to happen is this: when a JProgressBar changes, it has to tell the model that it changed so that listeners to the model (i.e. the JTree) can react accordingly (i.e. redraw the node). If your tree model extends DefaultTreeModel, which apparently it does, that would require you to call "model.nodeChanged(treeNode)" where "treeNode" is the TreeNode object which contains that JProgressBar.
Paul Statham
Ranch Hand

Joined: Dec 05, 2008
Posts: 56
Paul Clapham wrote:I didn't read most of your code, but what has to happen is this: when a JProgressBar changes, it has to tell the model that it changed so that listeners to the model (i.e. the JTree) can react accordingly (i.e. redraw the node). If your tree model extends DefaultTreeModel, which apparently it does, that would require you to call "model.nodeChanged(treeNode)" where "treeNode" is the TreeNode object which contains that JProgressBar.


Perfect thank you, I'm glad it was something simple!
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 174
Perfect thank you, I'm glad it was something simple!


- this notifier missing in JTree/DefaultTreeModel API

- you have to notify programatically by myTreeModel.nodeChanged()
 
Don't get me started about those stupid light bulbs.
 
subject: A JTree with JProgressBar's for its nodes
 
It's not a secret anymore!