So in this application I'm making, the user clicks on a button, and that button launches a program. This button will have the title of the application and the icon. I just need to know how to get the icon, kind of like this: Windows http://goo.gl/5WjdT
So what I want to know is this:
Thanks in advance!
Do you have to get the icon associated to the exe file of the application ? If so it is possible in java, take a look at this tutorial, that explain several ways of extracting app icon from an executable binary file from a Java application.
Take a look at this code :
String s = "c:/windows/regedit.exe";
File file = new File(s);
// Get metadata and create an icon
sun.awt.shell.ShellFolder sf =
sun.awt.shell.ShellFolder.getShellFolder(file);
Icon icon = new ImageIcon(sf.getIcon(true));
You can simply use FileSystemView for that purpose:
public static void main(String[] args) {
Icon icon = FileSystemView.getFileSystemView()
.getSystemIcon(new File("C:\\Windows\\regedit.exe"));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel(icon));
frame.pack();
frame.setVisible(true);
}
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