0

The version of the jdk is AmazonCoretto-17. I want to get the system icon of file.

I find that I can use the method "FileSystemView.getFileSystemView().getFileIcon(File)" to solve the problem, but the returned value is always null. I check the source code of the method, then I find that the method invokes the another method called "getIcon()" in the class "ShellFolder". As I check the source code of the latter, I find that the method always returns null. How can I solve the problem?

  • Depending on your OS, a sub class of `ShellFolder` is used. For instance, on Windows class `sun.awt.shell.Win32ShellFolder2` extends `ShellFolder` to actually implement icons. – Rob Spoor Aug 06 '23 at 12:05
  • The only other sub class I could find on GitHub is `sun.awt.shell.DefaultShellFolder` which doesn't override the icon methods, so I guess this only works on Windows. – Rob Spoor Aug 06 '23 at 12:09

1 Answers1

0

How can I solve the problem?

I assume that you are trying to use getSystemIcon not getFileIcon. (The latter doesn't exist!)

And I assume that you are trying to use it on a non-Windows platform. Unfortunately getSystemIcon on a non-Windows system will only give you a generic file or directory?

Why? Because that is all that they have implemented in the OpenJDK codebase!

But why? My guess is ... because there is no single standard way to get file type icons on generic Linux & Linux platforms. To illustrate, review the answers to this:

A Linux / Unix implementation in OpenJDK would need to interact with many different native window managers, each of which handle this issue differently. It would be a lot of work for the Java team to implement and maintain compatibility with a cat-herd of window managers.

While Oracle / OpenJDK Java are committed to supporting AWT + Swing as part of the Java platform, they don't appear to be investing many resources in enhancing them. You could say that HTML 5 and Android have won.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Generally, Swing considers Gnome the ’official’ environment on Linux. The system look & feel is com.sun.java.swing.plaf.gtk.GTKLookAndFeel. So, I would go with the XDG specification for Linux. – VGR Aug 06 '23 at 20:32
  • Yea ... but your typical Linux user doesn't like to be told what window manager to use. ("You are takin' away my freeeeedom") – Stephen C Aug 07 '23 at 04:09