On 17.04.2007, at 22:03, Michael Hall wrote:
For just the standard file and application icons, you could save
off instances and load the images yourself I would think.
The only other way I know of to get at icons from java involves
Swing...
private static final JFileChooser chooser = new JFileChooser();
private static final FileView fileview = chooser.getUI
().getFileView(chooser);
...
public void loadImage(File f) {
Icon tmpIcon = null;
tmpIcon = fileview.getIcon(f);
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?