Swing 如何在运行时选择jre?
我有一个Swing应用程序,我想用它运行。我有JRE的最新更新,我知道如何设置我的应用程序使用Nimbus look'n'feel using类,但我希望我的应用程序在运行时选择正确的JRE来使用Nimbus。怎么做Swing 如何在运行时选择jre?,swing,java,nimbus,Swing,Java,Nimbus,我有一个Swing应用程序,我想用它运行。我有JRE的最新更新,我知道如何设置我的应用程序使用Nimbus look'n'feel using类,但我希望我的应用程序在运行时选择正确的JRE来使用Nimbus。怎么做 我使用的是Netbeans。您不能在计算机上选择Java运行时。您所能做的就是测试某人的计算机上有哪些Java运行时可用 在代码中有两种选择 在Nimbus页面上,它们向您展示了如何使用Nimbus,如果Nimbus不可用,则返回到其他页面 try { for (LookA
我使用的是Netbeans。您不能在计算机上选择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测试人员的测试。重要的行是System.getProperty(“java.version”)
和System.getProperty(“java.vendor”)
Nimbus在Java 6 Update 10及更高版本上运行。您可以使用类似的本机启动器,它允许您明确地“使用捆绑的JRE或搜索给定版本范围内的最新Sun或IBM JRE/JDK。”
另外,请看。使用Java WebStart启动应用程序。这允许您请求系统上的最新JRE
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);
}
}