Java Swing Icon getFolderIcon()

Here you can find the source of getFolderIcon()

Description

Gets system default folder icon

License

Open Source License

Declaration

public static Icon getFolderIcon() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;

public class Main {
    /**/*from   w  w  w  .  j a v  a  2  s . co m*/
     * Cache of file icons
     */
    private static final Map<String, Icon> CACHE = new HashMap<String, Icon>();

    /**
     * Gets system default folder icon
     * @return
     */
    public static Icon getFolderIcon() {
        Icon icon;

        if (CACHE.containsKey("file-dir")) {
            icon = CACHE.get("file-dir");
        } else {
            File temp = new File(System.getProperty("java.io.tmpdir") + File.separator + "icon");
            temp.mkdirs();

            icon = FileSystemView.getFileSystemView().getSystemIcon(temp);

            CACHE.put("file-dir", icon);

            temp.delete();
        }

        return icon;
    }
}

Related

  1. getDefaultIcon()
  2. getDefaultIcon()
  3. getDefaultIcon()
  4. getEmptyIcon()
  5. getFolderIcon()
  6. getIcon(boolean isPressed, Icon baseIcon_)
  7. getIcon(Class baseclass, String name)
  8. getIcon(Class clazz, String path)
  9. getIcon(final String path)