代码之家  ›  专栏  ›  技术社区  ›  Ken

访问文件类型图标Mac OSX

  •  2
  • Ken  · 技术社区  · 15 年前

    我正试图找到一种方法来访问Mac OSX系统图标。有人知道他们在Mac电脑上的默认位置吗?或者知道如何使用Java将它们返回?

    有一种使用JFileChooser for Mac检索文件图标的方法,但该文件必须存在于文件系统中(在我的应用程序中,该文件可能是从服务器流式传输的,因此无法在具有该扩展名的系统上创建虚拟文件)。

    我可以用SWT在Windows上访问它们,方法如下(但这是Mac上的炸弹)。下面的变量“fileType”例如为“.txt”、“.bmp”、“.doc”等:

    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);
    

    更新:似乎没有明确的方法来导入这些。我最终在网上找到了一些通用的Mac图标,并将它们与我的应用捆绑在一起,以便在Mac上使用getResourceAsstream(),直到找到更好的解决方案。

    3 回复  |  直到 15 年前
        1
  •  3
  •   Béatrice Cassistat    15 年前

    已经很晚了,但也许有人会找同样的问题(比如我)。

    FileSystemView技巧仅适用于所有平台上的16x16图像。在Mac上,你需要使用默认的Aqua外观来让它工作。

    对于Mac,您可以使用一些Objective-C jni-libs附带的Quaqua,它为任何文件(16px、32、64、128、256、512)提供所需/可用的图标大小: http://www.randelshofer.ch/quaqua/javadoc/ch/randelshofer/quaqua/osx/OSXFile.html#getIcon%28java.io.File,%20int%29

        2
  •  2
  •   Sam Barnum    12 年前

    FileView FileSystemView . 我正在使用以下图标获取文件:

    final JFileChooser fc = new JFileChooser();
    //return fc.getFileView().getIcon(f); // will throw a  null pointer
    Icon result = fc.getUI().getFileView(fc).getIcon(f);
    
        3
  •  0
  •   akarnokd    15 年前