How do I get a file's icon in Java?
Asked Answered
F

1

11

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

Flail answered 6/12, 2010 at 4:34 Comment(2)
is this for all operating systems or just windows?Fogle
@Fogle All operating systems. [I know this is late, but I wanted it here in case someone else came by and had the same question]Flail
T
13
Icon icon = FileSystemView.getFileSystemView().getSystemIcon( File );
Tenure answered 6/12, 2010 at 4:41 Comment(3)
This doesn't work well on OS X, it only returns a folder for directories or a generic file icon for any non-directories.Marcellamarcelle
@SamBarnum is that still the case with Java 8 on OS X Yosemite?Flail
Workaround for os x: final javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); Icon icon = fc.getUI().getFileView(fc).getIcon(file);Schoenfeld

© 2022 - 2024 — McMap. All rights reserved.