特定节点的特定图标 [英] specific icon for specific node

查看:80
本文介绍了特定节点的特定图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在树模型中使用了jtree(所以我不能使用deafaulttreenode).我希望我的jtree根据其名称显示特定的图标.和".avi").感谢您的预先帮助!

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!

推荐答案

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:

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());
      }
    }
  }


这篇关于特定节点的特定图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆