views:

809

answers:

2

I am trying to find a way to access the Mac OSX system icons. Does anyone know their default location on a Mac? Or know of a way using Java to have them returned?

There is a method of using JFileChooser for Mac to retrieve an Icon for a file, but the file has to exist on the file system (in my app the file could be streaming from a server so short of creating a dummy file on the system with that extension it wont work).

I can access them on Windows in the following way using SWT (but this bombs on a Mac). The variable "fileType" below for example is ".txt", ".bmp", ".doc", etc:

Program p;
      Image image;

      //find the correct OS image for the file type and set
      //the image to the tree item
      p = Program.findProgram(fileType);
      ImageData data = p.getImageData();
      image = new Image(display, data);

UPDATE: There does not appear to be a clear way to import these. I ended up finding some generic Mac icons online and bundling them with my app to simply use getRecourceAsStream() when on a Mac until a better solution is found.

A: 

I think the FileSystemView and its friends provide way for getting file icons.

kd304
FileSystemView I saw can only return generic file icons. Icons like the hard drive icon on a mac desktop, or a folder. It doesnt support specific file types like MP3, DOC, PPT, XLS, etc.
Didn't know that as I'm a Win guy. Are you sure it does not work? There is also a weak option to use JNA calls into the OS to get file icons.
kd304
A: 

Hi,

It is late, but maybe somebody else would search for the same problem (like me).

The FileSystemView trick works only for 16x16 images on all platforms. On Mac, you need to use the default Aqua look and feel to make it work.

For Windows, you can use ShellFolder.getShellFolder(file).getIcon(true) to get a 32x32 icon.

For Mac, you can use Quaqua that comes with some Objective-C jni libs that give you the desired/available icon size for any file (16px, 32, 64, 128, 256, 512) : http://www.randelshofer.ch/quaqua/javadoc/ch/randelshofer/quaqua/osx/OSXFile.html#getIcon%28java.io.File,%20int%29

François Cassistat