Java Swing UIManager prepareGUI(final String appName)

Here you can find the source of prepareGUI(final String appName)

Description

Prepares the Swing GUI.

License

Open Source License

Parameter

Parameter Description
appName The application name. This is used to create the names of environment variables check for locale and theme overrides. appName "FooBar" for example uses the override environment variables FOOBAR_LANG and FOOBAR_THEME.

Exception

Parameter Description
Exception When preparing the GUI failed

Declaration


public static void prepareGUI(final String appName) throws Exception 

Method Source Code

//package com.java2s;
/*/*www  . ja v  a2  s.c om*/
 * Copyright (C) 2009 Klaus Reimer <k@ailis.de> 
 * See LICENSE.md for licensing information.
 */

import java.util.Locale;

import javax.swing.UIManager;

public class Main {
    /**
     * Prepares the Swing GUI.
     *
     * @param appName
     *            The application name. This is used to create the names of environment variables check for locale and
     *            theme overrides. appName "FooBar" for example uses the override environment variables FOOBAR_LANG and
     *            FOOBAR_THEME.
     * @throws Exception
     *             When preparing the GUI failed
     */

    public static void prepareGUI(final String appName) throws Exception {
        prepareLocale(appName.toUpperCase() + "_LANG");
        prepareTheme(appName.toUpperCase() + "_THEME");
    }

    /**
     * Prepares the locale. The language can be overridden with the specified environment variable. Set it to "de" to
     * enforce German language for example. The default is the system locale.
     *
     * @param overrideEnvVar
     *            The environment variable to check for override value. Must not be null.
     */

    public static void prepareLocale(final String overrideEnvVar) {
        final String language = System.getenv().get(overrideEnvVar);
        if (language != null) {
            Locale.setDefault(new Locale(language));
        }
    }

    /**
     * Prepares the theme. The theme can be overridden with the specified environment variable. The default is the
     * system look and feel.
     *
     * @param overrideEnvVar
     *            The environment variable to check for override value. Specify null for don't use override variable
     * @throws Exception
     *             When setting the theme failed
     */

    public static void prepareTheme(final String overrideEnvVar) throws Exception {
        final String sysThemeStr = overrideEnvVar == null ? null : System.getenv().get(overrideEnvVar);
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        if (sysThemeStr == null || Boolean.parseBoolean(sysThemeStr)) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
    }
}

Related

  1. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  2. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  3. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  4. paintUnderlying(Graphics g, JComponent c)
  5. paintXpTabHeader(int type, Graphics g, int x, int y, int width)
  6. prepareTheme(final String overrideEnvVar)
  7. printDefaults()
  8. printUIDefaults()
  9. setComponentLF(JComponent comp, String ui)