Wednesday, October 15, 2008

How to get System Icon in java

public Icon getSystemIcon(File f) {
    try {
      if (f != null) {
        ShellFolder sf = ShellFolder.getShellFolder(f);
        Image img = sf.getIcon(false);
        if (img != null) {
          return new ImageIcon(img, sf.getFolderType());
        }
        else {
          return UIManager.getIcon(f.isDirectory() ?
                                   "FileView.directoryIcon" :
                                   "FileView.fileIcon");
        }
      }
      else {
        return null;
      }
    }
    catch (FileNotFoundException ex) {
      return null;
    }
  }

No comments:

Post a Comment