• 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:

TreeNode ClassCastException?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, whats wrong with this code:



why that? this code is from a book so i think it is correct.

THANKS
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

the method getRoot() of interface javax.swing.tree.TreeModel returns an instance of class java.lang.Object. So the object returned is not necessarily an instance of class javax.swing.tree.TreeNode. Can you please post a working sample where we can reproduce your problem?

Stefan
 
Max Power
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, here it is. this code displays the filesystem inside a jtree. just start it with some existing path like c:\. after 3 seconds a method is called and the exception occurs.....


i can send you this code as well....?

THANKS IN ADVANCE :-)
 
Stefan Krompass
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Andreas Golchert:



This is the solution: Your getRoot()-method returns an instance of class File...

Stefan
 
Max Power
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, do you know how to change this?

thanks:-)
 
Stefan Krompass
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

what you have to do is distinguish between the types of nodes you click on... (leaf -> file, non-leaf -> directory). You could try using DefaultMutableTreeNode as a "wrapper" around your file-object. Just as a few suggestions...

Stefan
 
Max Power
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, thanks. can you go a bit more into detail?

i am still stuck...
 
Stefan Krompass
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

my solution yould look something like this. What I did, is to wrap the File-objects in DefaultMutableTreeNodes. We have to do this to separate the model (the File-objects) from the view (the nodes of the JTree).



Stefan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic