Dime
Dime

Reputation: 2071

set different look and feels in Swing Application Framework jsr 296

My application uses SAF (jsr 296). I want to use different look and feels on different platforms:

A default (Java) for Linux

And system (native) for Windows.

ADDED: So far I hardcoded L&F for the Windows OS in the startup() method of my Application class (as suggested by Joy and Thompson):

if (SystemUtils.IS_OS_WINDOWS) {
        UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
}

In the application.properties file, the default L&F is specified.

Is there no better way?

Upvotes: 0

Views: 1596

Answers (3)

Illya Yalovyy
Illya Yalovyy

Reputation: 1

you don't need so much code to do so. You can create a platform specific property file, or use "system" LnF in the application properties. More details at http://kenai.com/projects/bsaf

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168825

A default (Java) for Linux. ..system (native) for Windows.

if (System.getProperty("os.name").startsWith("Windows")) {
    try {
        UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Will set the look & feel for Windows to the native PLAF, while keeping the (default) Metal PLAF for Linux/Unix & using the default for Mac, which we are reliably informed is named:

com.apple.laf.AquaLookAndFeel

I would probably recommend Nimbus for the Linux/Unix machines. The Metal PLAF is so ..last millennium.

Upvotes: 3

Harry Joy
Harry Joy

Reputation: 59660

Try this:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

It will set look and feel based on system on which your application is running.

Upvotes: 3

Related Questions