• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

A JTree with JProgressBar's for its nodes

 
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
  • 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: 25805
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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()
 
What? What, what, what? What what tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic