English 中文(简体)
如何获得另一个应用程序的图标?
原标题:How to get the icon of another application?
  • 时间:2012-05-21 21:52:37
  •  标签:
  • java
  • windows

因此在这个应用程序中, 用户会点击一个按钮, 然后按钮会启动一个程序。 这个按钮将拥有应用程序和图标的标题。 我只需要知道如何获得图标, 比如 : < a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

所以我想知道的是:

  1. Is there any REAL way to do this in Java
  2. If so, how would you do it?

提前感谢!

最佳回答

您是否必须获得应用程序执行文件的图标? 如果在 java 中是可能的, 请查看 < a href=" http://www. rgagnon.com/javadetails/java-0 439. html" rel= “ noreferrer” > 此教程 < /a >, 解释从 Java 应用程序中从可执行的二进制文件提取应用程序图标的几种方法 。

看看这个代码:

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));
问题回答

您可以简单地为此使用文件系统视图 :

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);
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签