Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting Standard File Icons




On 25 Apr 2007, at 17:31, Daniel Dalquen wrote:

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?

The (x,y) parameters to paintIcon should be (0, 0). You should also call g.dispose() or Bad Things may happen.


Jerry


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Getting Standard File Icons (From: Daniel Dalquen <email@hidden>)
 >Re: Getting Standard File Icons (From: Michael Hall <email@hidden>)
 >Re: Getting Standard File Icons (From: Daniel Dalquen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.