我有一个Swing应用程序,我想用Nimbus look'n'feel来运行它。我有JRE的最新更新,我知道如何使用UIManager类设置我的应用程序以使用Nimbus look'n'feel,但我希望我的应用程序在运行时选择正确的JRE以使用Nimbus。怎么做?如何在运行时选择jre?
我正在使用Netbeans。
我有一个Swing应用程序,我想用Nimbus look'n'feel来运行它。我有JRE的最新更新,我知道如何使用UIManager类设置我的应用程序以使用Nimbus look'n'feel,但我希望我的应用程序在运行时选择正确的JRE以使用Nimbus。怎么做?如何在运行时选择jre?
我正在使用Netbeans。
您可以使用像Launch4J一个本机启动,它允许你明确“用捆绑的JRE工作或在特定的版本范围搜索最新的Sun或IBM JRE/JDK。”另外,请看this question。
您无法在计算机上选择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和更高版本上运行。
使用Java WebStart启动您的应用程序。这使您可以请求系统上的最新JRE。