Click here to Skip to main content
15,991,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,I am using jtree with my tree model(so I can't use deafaulttreenode).I want my jtree to show specific icons depend on their name.(Fx I want to show movie icon if my node name ends with ".avi").Thanks for your help in advance!
Posted

1 solution

Understanding the TreeModel[^]

You could check your node whether it is a file and then extract the file type ending. With that you can retrieve the file icon by searching for the program that supports this file from the OS:

Java
final int iSplit = strFileName.lastIndexOf('.') + 1;
  if (0 < iSplit) {
    final String strExtension = strFileName.substring(iSplit);
    if (null != strExtension) {
      final Program oProgram = Program.findProgram("." + strExtension);
      if (null != oProgram) {
        return new Image(Display.getCurrent(), oProgram.getImageData());
      }
    }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900