On 25 Apr 2007, at 17:31, Daniel Dalquen wrote:
Ok, so I fetch the Icon using either
FileSystemView.getFileSystemView() or the code above. Since the
rest of the GUI is done in SWT I have to convert it. Found this
snippet:
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/
org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet156.java
here's the code I use:
Icon icon = fileview.getIcon(new java.io.File("/Users/"));
BufferedImage buffIm = new BufferedImage
(32,32,BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffIm.createGraphics();
icon.paintIcon(new Canvas(), g,32, 32);
Image swtIm = new Image(null,convertToSWT(buffIm));
Unfortunately, this gives me a black 32x32px square instead of an
icon. Using TYPE_INT_ARGB I get an ArrayIndexOutOfBoundsException.
What am I doing wrong?
The (x,y) parameters to paintIcon should be (0, 0). You should also
call g.dispose() or Bad Things may happen.