How to display system icon for a file in SWT?

后端 未结 4 1553
谎友^
谎友^ 2021-01-02 04:40

I want to display a file tree similarly to java2s.com \'Create a lazy file tree\', but include the actual system icons - especially for folders. SWT does not seem to offer t

4条回答
  •  情书的邮戳
    2021-01-02 05:23

    For files, you can use org.eclipse.swt.program.Program to obtain an icon (with correct set transparency) for a given file ending:

    File file=...
    String fileEnding = file.getName().substring(file.getName().lastIndexOf('.'));
    ImageData iconData=Program.findProgram(fileEnding ).getImageData();
    Image icon= new Image(Display.getCurrent(), iconData);
    

    For folders, you might consider just using a static icon.

提交回复
热议问题