I list some filenames with their icons (like the ones in the Windows Explorer) in a JTable
. I know the two ways to get the icon if I have a File
object from the local file system:
javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon( file )
for a 16x16 icon or for a bigger one:
sun.awt.shell.ShellFolder.getShellFolder( file ).getIcon( true ) )
Since my files are stored in a database, I don't have the File
object. My workaround is to create a temp file with the specific filename extension, use one of the two methods above and cache the icon to display it in a CellRenderer.
I searched for a solution without temporary files and found two I don't like either:
org.eclipse.swt.program.Program.findProgram(String extension).getImageData()
, but I don't want to use SWTorg.jdesktop.jdic.icons.IconService
from the Incubator of the JDIC project. The last changes on the IconService
are 6 years ago, on JDIC 2 years ago and I can't find a downloadable jar.Is there another solution?
Right click extension whose icon you want to change and then select “Edit Selected File Type.” In the “Edit File Type” window, click the “…” button to the right of the Default Icon text field. The “Change Icon” window shows some basic icons, but click the “Browse” button to find your own icon files.
The ICO file format is an image file format for computer icons in Microsoft Windows.
ICON files are typically saved as small, square bitmap images, ranging from 16 x 16 to 256 x 256 pixels in size. Most Windows Icon files use the . ICO extension.
Looks like you already discovered the way to do it, unless you want to dive into native libraries etc.
FileSystemView uses Win32ShellFolder internally so they are basically the same.
I also dug up the Source for org.eclipse.swt.program.Program and with it org.eclipse.swt.internal.win32.OS. The OS class then uses a native call for the Icon. At this point unless you really really cannot create a Temp File i would not go down that path.
For JDIC i only found http://kickjava.com/src/org/jdesktop/jdic/tray/internal/impl/WinTrayIconService.java.htm with a little bit of digging(may not be related but does icony things :D). Also calls native.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With