如何在运行时选择jre?

发布于 2024-09-06 10:43:11 字数 384 浏览 3 评论 0原文

我有一个 Swing 应用程序,我想用 Nimbus 外观来运行它'n'感觉。我有 JRE 的最新更新,并且我知道如何使用 UIManager 类,但我希望我的应用程序在运行时选择正确的 JRE 来使用 Nimbus。怎么做呢?

我正在使用 Netbeans。

i have a Swing app and i want to run it with Nimbus look'n'feel. I have the last update for the JRE and I know how to setup my app to use Nimbus look'n'feel using UIManager class, but I want my app to choose the right JRE on runtime to use Nimbus. How to do that?

I am using Netbeans.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妞丶爷亲个 2024-09-13 10:43:11

您可以使用像 Launch4J 这样的本机启动器,它允许您显式“使用捆绑的 JRE 或搜索给定版本范围内最新的 Sun 或 IBM JRE / JDK。。

另外,请查看此问题

You can use a native launcher like Launch4J which allows you to explicitly "Work with a bundled JRE or search for newest Sun or IBM JRE / JDK in given version range."

Also, take a look at this question.

变身佩奇 2024-09-13 10:43:11

您无法选择计算机上的 Java 运行时。您所能做的就是测试某人计算机上可用的 Java 运行时。

对于在代码中执行的操作,您有两种选择。

在 Nimbus 页面上,他们向您展示了如何测试Nimbus 的外观和感觉,如果 Nimbus 不可用,则回退到其他内容。

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

这是 Oracle 建议开发人员这样做的。

您的另一个选择是运行测试以查看可用的 Java 运行时环境。这是 Java Tester 中执行测试的 小程序。重要的行是 System.getProperty("java.version")System.getProperty("java.vendor")

public class JavaVersionDisplayApplet extends Applet
 { private Label m_labVersionVendor; 
   public JavaVersionDisplayApplet() //constructor
   { Color colFrameBackground = Color.pink;
     this.setBackground(colFrameBackground);
     m_labVersionVendor = new Label (" Java Version: " +
                                    System.getProperty("java.version")+
                           " from "+System.getProperty("java.vendor"));
     this.add(m_labVersionVendor);
   }
 }

Nimbus 在 Java 6 Update 10 及更高版本上运行。

You don't get to choose the Java run time on a computer. All you can do is test for what Java run time is available on someone's computer.

You have two choices for what to do in your code.

On the Nimbus page, they show you how you can test for the Nimbus look and feel, and fall back to something else if Nimbus is not available.

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

This is what Oracle recommends developers do.

Your other choice is to run a test to see what Java run time environment is available. Here's an applet from Java Tester that performs the test. The important lines are System.getProperty("java.version") and System.getProperty("java.vendor").

public class JavaVersionDisplayApplet extends Applet
 { private Label m_labVersionVendor; 
   public JavaVersionDisplayApplet() //constructor
   { Color colFrameBackground = Color.pink;
     this.setBackground(colFrameBackground);
     m_labVersionVendor = new Label (" Java Version: " +
                                    System.getProperty("java.version")+
                           " from "+System.getProperty("java.vendor"));
     this.add(m_labVersionVendor);
   }
 }

Nimbus runs on Java 6 Update 10 and higher.

寄人书 2024-09-13 10:43:11

使用 Java WebStart 启动您的应用程序。这允许您请求系统上最新的 JRE。

Use Java WebStart to launch your application. This allows you to ask for the newest JRE on the system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文