Java Swing Look and Feel isWindowsUI()

Here you can find the source of isWindowsUI()

Description

Check if we are using one of the Windows Look and Feels.

License

Open Source License

Return

True iff the current LAF is "Windows" or "Windows Classic"

Declaration

public static boolean isWindowsUI() 

Method Source Code

//package com.java2s;
/*/*from   w ww.j a  v  a 2  s.  c  o m*/
 * Copyright (c) 2006-2017 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
 * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

public class Main {
    /**
     * Windows LAF class name.
     */
    private static final String WINDOWSUI = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    /**
     * Windows classic LAF class name.
     */
    private static final String WINDOWSCLASSICUI = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";

    /**
     * Check if we are using one of the Windows Look and Feels.
     *
     * @return True iff the current LAF is "Windows" or "Windows Classic"
     */
    public static boolean isWindowsUI() {
        return isWindowsNewUI() || isWindowsClassicUI();
    }

    /**
     * Check if we are using the new Windows Look and Feel.
     *
     * @return true iif the current LAF is Windows
     */
    public static boolean isWindowsNewUI() {
        return WINDOWSUI.equals(UIManager.getLookAndFeel().getClass().getName());
    }

    /**
     * Check if we are using the new Windows Classic Look and Feel.
     *
     * @return true iif the current LAF is Windows Classic
     */
    public static boolean isWindowsClassicUI() {
        return WINDOWSCLASSICUI.equals(UIManager.getLookAndFeel().getClass().getName());
    }

    /**
     * Returns the class name of the look and feel from its display name.
     *
     * @param displayName Look and feel display name
     *
     * @return Look and feel class name or a zero length string
     */
    public static String getLookAndFeel(final String displayName) {
        if (displayName == null || displayName.isEmpty() || "Native".equals(displayName)) {
            return UIManager.getSystemLookAndFeelClassName();
        }

        final StringBuilder classNameBuilder = new StringBuilder();

        for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
            if (laf.getName().equals(displayName)) {
                classNameBuilder.append(laf.getClassName());
                break;
            }
        }

        if (classNameBuilder.length() == 0) {
            classNameBuilder.append(UIManager.getSystemLookAndFeelClassName());
        }

        return classNameBuilder.toString();
    }
}

Related

  1. isWindowsClassicLookAndFeel()
  2. isWindowsLaF()
  3. isWindowsLookAndFeel()
  4. isWindowsLookAndFeel()
  5. isWindowsModernLookAndFeel()
  6. isWindowsVistaLookAndFeel()
  7. isWindowsXPLookAndFeel()
  8. isWinLAF()
  9. isWinLAF()