如何在运行时选择jre?

时间:2010-06-21 15:18:42

标签: swing java nimbus

我有一个Swing应用程序,我想用Nimbus look'n'feel运行它。我有JRE的最后一次更新,我知道如何使用UIManager类设置我的应用程序以使用Nimbus look'n'feel,但我希望我的应用程序在运行时选择正确的JRE以使用Nimbus。怎么做?

我正在使用Netbeans。

3 个答案:

答案 0 :(得分:1)

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

您有两种选择,可以在代码中执行操作。

在Nimbus页面上,他们会向您展示如何test for the Nimbus look and feel,如果没有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的applet,用于执行测试。重要的行是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及更高版本上运行。

答案 1 :(得分:1)

您可以使用像Launch4J这样的原生启动器,它允许您明确地“使用捆绑的JRE或在给定版本范围内搜索最新的Sun或IBM JRE / JDK 。”< / p>

另外,请查看this question

答案 2 :(得分:0)

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

相关问题