get File System Icon - Java Swing

Java examples for Swing:Icon

Description

get File System Icon

Demo Code


//package com.java2s;
import javax.swing.*;

import java.io.File;
import java.io.IOException;

import javax.swing.filechooser.FileSystemView;

public class Main {
    public static Icon getFileSystemIcon(String extension) {
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.pathSeparator + System.currentTimeMillis() + "."
                + extension);//from  w w  w  . ja v a 2  s .  c  om
        try {
            file.createNewFile();
        } catch (IOException ex) {
            Thread.currentThread().getUncaughtExceptionHandler()
                    .uncaughtException(Thread.currentThread(), ex);
        }
        file.deleteOnExit();
        return FileSystemView.getFileSystemView().getSystemIcon(file);
    }
}

Related Tutorials