gpt4 book ai didi

java - Runnable jar 不使用 Apple 的方法

转载 作者:行者123 更新时间:2023-12-01 13:41:05 26 4
gpt4 key购买 nike

我已将 java 程序导出到可运行的 jar 文件,除了一些方法外,它运行良好。当我使用苹果的方法时,例如..

System.setProperty("apple.laf.useScreenMenuBar", "true");

..和..

Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor");

..它们在 Eclipse 中工作,但不在可运行 jar 中运行。我该如何解决这个问题?

最佳答案

很难从片段中知道原因,但是,根据 Java Runtime System Properties您可以将它们作为 Java 命令的一部分传递,

java -Dapple.laf.useScreenMenuBar="true" com.example.yourApp

或者将它们设置为 System.setProperty 的一部分,但您应该在 AWT/Swing 库的任何部分有机会初始化之前执行此操作。

When setting a property within your application (using System.setProperty), make sure that it is one of the first statements made inside of your main method. Doing so sets the property before AWT is loaded, ensuring that it takes effect.

或者您可以将应用程序打包为应用程序包,然后您可以将设置作为 Info.plist 的一部分提供,如所示 here

关于java - Runnable jar 不使用 Apple 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20770290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com