Java examples for Swing:Icon
get File System Icon
//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); } }