javaswinglook-and-feeljsr296

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?


Solution

  • 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.