• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

custom icons in JTree

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'm stumped
trying to use custom icons for the nodes in a JTree
I made my own TreeCellRenderer



and I used it like this when I create and populate my tree



I run the code in a debugger and everything seems to work right but on the GUI there are just default icons
I even made a JLabel and set the icon to display in it and that works so the image is getting loaded
I'm guessing there's something wrong with the order in which I'm doing things, like when stuff get's created but it looks right to me
I can put a breakpoint in MyTreeCellRenderer and see the code jump in there

any ideas???

Dave
 
Sheriff
Posts: 28368
99
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
Do your tree nodes REALLY contain DefaultMutableTreeNode objects as their user objects? If not, then your renderer would be throwing a class-cast exception where you cast the value to that type. And if you do, that's a really strange design.
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my nodes are objects that extend DefaultMutableTreeNodes
they're extended such that they contain info about how to lookup stuff for that node in a database
the functions I'm calling, set*Icon haven't been overloaded so I think what I'm doing is ok, but I could be wrong
I have been before

Dave
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm, Paul
I think you're onto something
investigating further
thanks

Dave
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doh
what's behind door number 3
it would be a "really strange design" :roll:
I shouldn't extend DefaultMutableTree node like I'm doing
I should use setUserObject to include the additional info
my bad

Thanks
Dave
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, found the problem
the folks who think IDE's are terrible and you should write all your code with a text editor are gonna laugh
after I built my nice little tree with all the custom icons, the auto-generated code that netbeans had written came along behind me and re-initialized my tree
interestingly, now that I've found the problem I see that creating my own treenodes that extend a DefaultMutableTreeNode isn't a problem
I didn't think it should be
but now that I see how I can use setUserObject to do the same thing I see that it's kinda a waste of time

Thanks for all the help
Dave
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic