Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Multiple Icons at once for JTree

794029Aug 13 2009 — edited Aug 14 2009
Hi, i want to have several different icons for a JTree at the same time.

Currently i have a GUI that creates a JTree that has a folder as the root, and a list of files/subfolders under it - (root is based on user input)

Anyhow, i want different files to have different icons. Such as a different Icon for .txt files and another for .doc files.

I have look on the tutorials, but it mostly talks about 1 icon for all leaf nodes, and a different for directories.

Will i have to change my current tree type to do this? i just have a JTree. Is there some kind of mutableJTree? i couldnt find one.

I wish i could just do something like:
for(int row =0; row <MyTree.getRowCount(); row++)
 {
       String s =  MyTree.getNodeName(row);
       File f = new File(s);
        if( hasSomeDefinedProperty(f) )
          {
             MyTree.getNode(row).setIcon( myIcon );
          }
}

public boolean hasSomeDefinedProperty(File f)
{
   // check for some property, such as file type, or a certain string in the File.
}
Is there even a simple metod such as " MyTree.getNode(row).setIcon( myIcon );"

I cant even find a ".getNode(row)" method for JTree... Anyone have ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 11 2009
Added on Aug 13 2009
11 comments
415 views