• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A JTree with JProgressBar's for its nodes

 
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic