Java Swing Look and Feel setCoolLookAndFeel()

Here you can find the source of setCoolLookAndFeel()

Description

Tries to set the NimbusLookAndFeel or (if Nibus is not available) the OS like LookAndFeel

License

Open Source License

Return

true if the LookAndFeel could be changed

Declaration

public static boolean setCoolLookAndFeel() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

public class Main {
    /**//w w w.java2  s. com
     * Tries to set the NimbusLookAndFeel or (if Nibus is not available) the OS like
     * LookAndFeel
     * 
     * @return true if the LookAndFeel could be changed
     */
    public static boolean setCoolLookAndFeel() {
        return (setNimbusLookAndFeel() || setSystemLookAndFeel());
    }

    /**
     * Tries to set the NimbusLookAndFeel
     * 
     * @return if the NimbusLookAndFeel could bet set
     */
    public static boolean setNimbusLookAndFeel() {
        boolean isNumbusSet = true;
        try { // Nimbus Loyout
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException e) {
            isNumbusSet = false;
        } catch (InstantiationException e) {
            isNumbusSet = false;
        } catch (IllegalAccessException e) {
            isNumbusSet = false;
        } catch (UnsupportedLookAndFeelException e) {
            isNumbusSet = false;
        }
        return isNumbusSet;

        /*
         * try {//alternative way for (LookAndFeelInfo info :
         * UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) {
         * UIManager.setLookAndFeel(info.getClassName()); break; } } } catch
         * (UnsupportedLookAndFeelException e) { } catch (ClassNotFoundException e) { } catch
         * (InstantiationException e) { } catch (IllegalAccessException e) { }
         */
    }

    /**
     * Tries to set the LookAndFeel to the os default
     * 
     * @return if the system look and feel could be set
     */
    public static boolean setSystemLookAndFeel() {
        boolean isSystemLookAndFeelSet = true;
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            isSystemLookAndFeelSet = false;
        }
        return isSystemLookAndFeelSet;
    }
}

Related

  1. metalLookAndFeel()
  2. nativeLook()
  3. printInstalledLookAndFeel()
  4. printInstalledPLAFs()
  5. setBestLookAndFeelAvailable()
  6. setDefaultLookAndFeel()
  7. setDefaultLookandfeel()
  8. setJavaLookAndFeel()
  9. setJavaLookAndFeel()