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
I haven't looked at the code in detail, but I notice you are using TYPE_INT_RGB instead of TYPE_INT_ARGB (which includes alpha/transparency support).
Looking at Snippet32 on the Eclipse site, I can see that you can usually pick up icons using the Program class. Using the extension ".Folder" doesn't seem to return an instance, even though it is a member of getExtensions().
This code can get a folder icon:
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, SWT.NONE);
label.setText("Can't find icon");
Image image = null;
for (Program p : Program.getPrograms()) {
if ("Folder".equals(p.getName())) {
ImageData data = p.getImageData();
if (data != null) {
image = new Image(display, data);
label.setImage(image);
}
break;
}
}
label.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
if (image != null)
image.dispose();
display.dispose();
That code needs refined, I think, but should be a pointer in the right direction. I only tested on English-language Windows XP.