11

I'm making a basic file browser and wish to display the icon of each file. Is there any way to get this?

Ky -
  • 30,724
  • 51
  • 192
  • 308

1 Answers1

13
Icon icon = FileSystemView.getFileSystemView().getSystemIcon( File );
camickr
  • 321,443
  • 19
  • 166
  • 288
  • 2
    This doesn't work well on OS X, it only returns a folder for directories or a generic file icon for any non-directories. – Sam Barnum Dec 15 '12 at 04:16
  • @SamBarnum is that still the case with Java 8 on OS X Yosemite? – Ky - Dec 11 '14 at 06:54
  • 2
    Workaround for os x: `final javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); Icon icon = fc.getUI().getFileView(fc).getIcon(file);` – zella Oct 21 '15 at 07:43