以编程方式更改Application Dock图标javaFX [英] Changing Application Dock Icon javaFX programmatically
问题描述
我有一个只能从JAR加载的javaFX应用程序,但是我想更改Mac Dock中的图标.我已经设法在Windows上解决了.我正在使用Netbeans IDE,并且希望不添加其他apple JAR Extension文件.因此,我不确定是否可行.
I have a javaFX Application that will only load from a JAR however I wanted to change the icon in the mac dock. I have managed to working it out on windows. I am using Netbeans IDE, and would prefer to not add the additional apple JAR Extension file. It is because of this I’m not sure if it is possible.
推荐答案
到目前为止,我还没有看到使用JavaFX做到这一点的方法,但是有一种使用Apple特定的Java API做到这一点的方法:
So far I haven't seen a way to do this with JavaFX but there is a way to do it with Apple-specific Java APIs:
public static void main(String[] args) {
try {
URL iconURL = Main.class.getResource("ui/resources/Logo@2x.png");
Image image = new ImageIcon(iconURL).getImage();
com.apple.eawt.Application.getApplication().setDockIconImage(image);
} catch (Exception e) {
// Won't work on Windows or Linux.
}
launch(args);
}
这至少适用于Oracle Java 1.7.0_40和1.8.0_25.
This works at least with Oracle Java 1.7.0_40 and 1.8.0_25.
缺点是,当您启动JAR时,您会在坞站中看到Java徽标很短的时间,然后将其更改为图标.这是一个技术限制,只能通过创建真实的本机OS X捆绑软件来解决.
The downside is that when you start the JAR, you'll see the Java logo in the dock for a short time which then changes to your icon. This is a technical limitation and can only be worked around by creating a real, native OS X bundle.
这篇关于以编程方式更改Application Dock图标javaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!