10

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

Ky.
  • 28,753
  • 48
  • 180
  • 285
  • is this for all operating systems or just windows? – pstanton Dec 06 '10 at 04:39
  • @pstanton All operating systems. [I know this is late, but I wanted it here in case someone else came by and had the same question] – Ky. Oct 01 '16 at 06:43

1 Answers1

11
Icon icon = FileSystemView.getFileSystemView().getSystemIcon( File );
camickr
  • 316,400
  • 19
  • 155
  • 279
  • 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