views:

57

answers:

3

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.

+1  A: 

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.

Gilbert Le Blanc
+1  A: 

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.

Camilo Díaz
A: 

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

Thorbjørn Ravn Andersen