I'm making a basic file browser and wish to display the icon of each file. Is there any way to get this?
How do I get a file's icon in Java?
Asked Answered
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
Icon icon = FileSystemView.getFileSystemView().getSystemIcon( File );
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.