# Class UIManager

java.lang.Object
com.codename1.ui.plaf.UIManager

public class UIManager extends Object
Central point singleton managing the look of the application, this class allows us to customize the styles (themes) as well as the look instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addThemeProps(Hashtable themeProps)`
  Adds the given theme properties on top of the existing properties without clearing the existing theme first
  `void`
  `addThemeRefreshListener(ActionListener l)`
  Adds a Theme refresh listener.
  `static UIManager`
  `createInstance()`
  This factory method allows creating a new UIManager instance, this is usefull where an application has some screens with different context
  `Map<String,String>`
  `getBundle()`
  The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
  `Style`
  `getComponentCustomStyle(String id, String type)`
  Returns a custom style for the component with the given id, this method always returns a new instance.
  `Style`
  `getComponentSelectedStyle(String id)`
  Returns the selected style of the component with the given id or a new instance of the default style.
  `final Style`
  `getComponentStyle(String id)`
  Returns the style of the component with the given id or a new instance of the default style.
  `String`
  `getIconUIIDFor(String id)`
  Gets the IconUIID for the given UIID.
  `static UIManager`
  `getInstance()`
  Singleton instance method
  `LookAndFeel`
  `getLookAndFeel()`
  Returns the currently installed look and feel
  `Hashtable`
  `getResourceBundle()`
  The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
  `int`
  `getThemeConstant(String constantName, int def)`
  Returns a theme constant defined in the resource editor
  `final String`
  `getThemeConstant(String constantName, String def)`
  Returns a theme constant defined in the resource editor
  `Image`
  `getThemeImageConstant(String constantName)`
  Returns a theme constant defined in the resource editor
  `Object`
  `getThemeMaskConstant(String constantName)`
  Returns a theme mask constant
  `String`
  `getThemeName()`

  ###### Returns

  `static Resources`
  `initFirstTheme(String resourceFile)`
  This is a shorthand notation for boilerplate code for initializing the first theme in the given resource file and catching/doing nothing with the IOException since this would be invoked too early in the program where we would be out of options if something like that happens.
  `static Resources`
  `initNamedTheme(String resourceFile, String resName)`
  Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource name
  `Boolean`
  `isThemeConstant(String constantName)`
  Returns a theme constant defined in the resource editor as a boolean value or null if the constant isn't defined
  `final boolean`
  `isThemeConstant(String constantName, boolean def)`
  Returns a theme constant defined in the resource editor as a boolean value
  `boolean`
  `isUseLargerTextScale()`
  Checks if larger text scaling is enabled.
  `final String`
  `localize(String key, String defaultValue)`
  Localizes the given string from the resource bundle if such a String exists in the resource bundle.
  `protected void`
  `onLocalize(String key, String defaultValue)`
  Callback for subclasses that wish to track localization invocations.
  `Style`
  `parseComponentCustomStyle(Resources theme, String baseStyle, String id, String type, String... styleString)`
  Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.
  `Style`
  `parseComponentSelectedStyle(Resources theme, String baseStyle, String id, String... styleString)`
  Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.
  `Style`
  `parseComponentStyle(Resources theme, String baseStyle, String id, String... styleString)`
  Returns the style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.
  `void`
  `refreshTheme()`
  Invalidates the cached Style instances and re-runs the theme build pass against the currently installed theme properties.
  `void`
  `removeThemeRefreshListener(ActionListener l)`
  Removes a Theme refresh listener.
  `void`
  `setBundle(Map<String,String> bundle)`
  The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
  `void`
  `setComponentSelectedStyle(String id, Style style)`
  Allows a developer to programmatically install a style into the UI manager
  `void`
  `setComponentStyle(String id, Style style)`
  Allows a developer to programmatically install a style into the UI manager
  `void`
  `setComponentStyle(String id, Style style, String type)`
  Allows a developer to programmatically install a style into the UI manager
  `void`
  `setLookAndFeel(LookAndFeel plaf)`
  Sets the currently installed look and feel
  `void`
  `setResourceBundle(Hashtable resourceBundle)`
  The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
  `void`
  `setThemeProps(Hashtable themeProps)`
  Allows manual theme loading from a hashtable of key/value pairs
  `void`
  `setUseLargerTextScale(boolean useLargerTextScale)`
  Enables or disables scaling fonts when larger text is enabled on the device.
  `boolean`
  `wasThemeInstalled()`
  Indicates if a theme was previously installed since the last reset
  `void`
  `zoomFonts(float factor)`
  Scales the font sizes of the current theme by the given factor, e.g.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getInstance

    public static UIManager getInstance()

    Singleton instance method

    ###### Returns

    Instance of the ui manager

  - ### createInstance

    public static UIManager createInstance()

    This factory method allows creating a new UIManager instance, this is usefull where an application has some screens with different context

    ###### Returns

    a new UIManager instance

  - ### initFirstTheme

    public static Resources initFirstTheme(String resourceFile)

    This is a shorthand notation for boilerplate code for initializing the first theme in the given resource file and catching/doing nothing with the IOException since this would be invoked too early in the program where we would be out of options if something like that happens. Effectively this is the same as writing:

        Resources theme = null;
        try {
            theme = Resources.openLayered(resourceFile);
            UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
        } catch (IOException e) {
            Log.e(e);
        }

    ###### Parameters

    - `resourceFile`: the name of the resource file starting with / and without the res extension

    ###### Returns

    the resource file or null in case of a failure

  - ### initNamedTheme

    public static Resources initNamedTheme(String resourceFile, String resName)

    Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource name

    ###### Parameters

    - `resourceFile`: the name of the resource file starting with / and without the res extension

    - `resName`: the name of the theme to use from the file if it contains more than one theme

    ###### Returns

    the resource file or null in case of a failure

  - ### isUseLargerTextScale

    public boolean isUseLargerTextScale()

    Checks if larger text scaling is enabled.

    ###### Returns

    true if larger text scaling should be applied.

  - ### setUseLargerTextScale

    public void setUseLargerTextScale(boolean useLargerTextScale)

    Enables or disables scaling fonts when larger text is enabled on the device. This can also be enabled via the `useLargerTextScaleBool` theme constant.

    ###### Parameters

    - `useLargerTextScale`: @param useLargerTextScale true to apply `Display#getLargerTextScale()` when `Display#isLargerTextEnabled()` is true.

  - ### wasThemeInstalled

    public boolean wasThemeInstalled()

    Indicates if a theme was previously installed since the last reset

    ###### Returns

    true if setThemeProps was invoked

  - ### getLookAndFeel

    public LookAndFeel getLookAndFeel()

    Returns the currently installed look and feel

    ###### Returns

    the currently installed look and feel

  - ### setLookAndFeel

    public void setLookAndFeel(LookAndFeel plaf)

    Sets the currently installed look and feel

    ###### Parameters

    - `plaf`: the look and feel for the application

  - ### setComponentStyle

    public void setComponentStyle(String id, Style style)

    Allows a developer to programmatically install a style into the UI manager

    ###### Parameters

    - `id`: the component id matching the given style

    - `style`: the style object to install

  - ### setComponentStyle

    public void setComponentStyle(String id, Style style, String type)

    Allows a developer to programmatically install a style into the UI manager

    ###### Parameters

    - `id`: the component id matching the given style

    - `style`: the style object to install

    - `type`: press, dis or other custom type

  - ### setComponentSelectedStyle

    public void setComponentSelectedStyle(String id, Style style)

    Allows a developer to programmatically install a style into the UI manager

    ###### Parameters

    - `id`: the component id matching the given style

    - `style`: the style object to install

  - ### getComponentStyle

    public final Style getComponentStyle(String id)

    Returns the style of the component with the given id or a new instance of the default style. This method will always return a new style instance to prevent modification of the global style object.

    ###### Parameters

    - `id`: the component id whose style we want

    ###### Returns

    the appropriate style (this method never returns null)

  - ### getIconUIIDFor

    public String getIconUIIDFor(String id)

    Gets the IconUIID for the given UIID. If the theme defines a style that is named ${id}Icon (i.e. the id with "Icon" suffix) such that it derives from id, then this style is deemed to be the icon style corresponding with id.

    ###### Parameters

    - `id`: The UIID to check for a companion UIID.

    ###### Returns

    The IconUIID corresponding to the given ID - or null if none is defined in the theme.

    ###### Since

    8.0

  - ### parseComponentStyle

    public Style parseComponentStyle(Resources theme, String baseStyle, String id, String... styleString)

    Returns the style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.

    This method will always return a new style instance to prevent modification of the global style object.

    ###### Parameters

    - `theme`: Theme file used to retrieve images that are referenced by the styleString

    - `baseStyle`: @param baseStyle The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString.

    - `id`: the component id into which the resulting style is to be cached.

    - `styleString`: @param styleString Array of style strings to override the styles in baseStyle. Style string syntax is is key1:value1; key2:value2; key3:value3; etc.... While this is similar to CSS, it is not CSS. The keys and values correspond to properties of `Style` and their associated values.

    ###### Returns

    the appropriate style (this method never returns null)

  - ### getComponentSelectedStyle

    public Style getComponentSelectedStyle(String id)

    Returns the selected style of the component with the given id or a new instance of the default style. This method will always return a new style instance to prevent modification of the global style object.

    ###### Parameters

    - `id`: the component id whose selected style we want

    ###### Returns

    the appropriate style (this method never returns null)

  - ### parseComponentSelectedStyle

    public Style parseComponentSelectedStyle(Resources theme, String baseStyle, String id, String... styleString)

    Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.

    This method will always return a new style instance to prevent modification of the global style object.

    ###### Parameters

    - `theme`: Theme file used to retrieve images that are referenced by the styleString

    - `baseStyle`: @param baseStyle The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString.

    - `id`: the component id into which the resulting style is to be cached.

    - `styleString`: @param styleString Array of style strings to override the styles in baseStyle. Style string syntax is is key1:value1; key2:value2; key3:value3; etc.... While this is similar to CSS, it is not CSS. The keys and values correspond to properties of `Style` and their associated values.

    ###### Returns

    the appropriate style (this method never returns null)

  - ### getComponentCustomStyle

    public Style getComponentCustomStyle(String id, String type)

    Returns a custom style for the component with the given id, this method always returns a new instance. Custom styles allow us to install application specific or component specific style attributes such as pressed, disabled, hover etc.

    ###### Parameters

    - `id`: the component id whose custom style we want

    - `type`: the style type

    ###### Returns

    the appropriate style (this method never returns null)

  - ### parseComponentCustomStyle

    public Style parseComponentCustomStyle(Resources theme, String baseStyle, String id, String type, String... styleString)

    Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.

    This method will always return a new style instance to prevent modification of the global style object.

    ###### Parameters

    - `theme`: Theme file used to retrieve images that are referenced by the styleString

    - `baseStyle`: @param baseStyle The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString.

    - `id`: the component id into which the resulting style is to be cached.

    - `type`: the style type

    - `styleString`: @param styleString Array of style strings to override the styles in baseStyle. Style string syntax is is key1:value1; key2:value2; key3:value3; etc.... While this is similar to CSS, it is not CSS. The keys and values correspond to properties of `Style` and their associated values.

    ###### Returns

    the appropriate style (this method never returns null)

  - ### getThemeName

    public String getThemeName()

    ###### Returns

    the name of the current theme for theme switching UI's

  - ### setThemeProps

    public void setThemeProps(Hashtable themeProps)

    Allows manual theme loading from a hashtable of key/value pairs

    ###### Parameters

    - `themeProps`: the properties of the given theme

  - ### addThemeProps

    public void addThemeProps(Hashtable themeProps)

    Adds the given theme properties on top of the existing properties without clearing the existing theme first

    ###### Parameters

    - `themeProps`: the properties of the given theme

  - ### zoomFonts

    public void zoomFonts(float factor)

    Scales the font sizes of the current theme by the given factor, e.g. a factor of 1.2 increases all font sizes by 20% and a factor of 0.8 decreases them by 20%. Only fonts that support scaling (TTF or native: fonts, see `Font.isTTFNativeFont()`) are affected; system fonts are skipped since their size is fixed by the underlying platform.

    The zoom is applied relative to the current state of the theme, so calling this method repeatedly compounds the effect. To undo a zoom, either reapply the theme or call this method with the reciprocal factor.

    Note: this updates the theme definitions and clears the cached styles, but components already shown on a form continue to render with the Font instances they captured before the call. To apply the new sizes to a live form, invoke `refreshTheme()` on it (typically `Form.getCurrentForm().refreshTheme()`) after calling this method.

    ###### Parameters

    - `factor`: the multiplier applied to every scalable font size. Must be greater than zero.

  - ### refreshTheme

    public void refreshTheme()
    Invalidates the cached Style instances and re-runs the theme build pass against the currently installed theme properties. Callers use this after state changes that affect style resolution (notably `Display.setDarkMode`, which makes `$Dark<UIID>` entries eligible) without reloading the theme from a resource file. Components styled after this call resolve against the refreshed theme; already-resolved Style references on existing components keep their old values until those components re-fetch their styles.

  - ### getThemeConstant

    public int getThemeConstant(String constantName, int def)

    Returns a theme constant defined in the resource editor

    ###### Parameters

    - `constantName`: the name of the constant

    - `def`: default value

    ###### Returns

    the value of the constant or the default if the constant isn't in the theme

  - ### getThemeConstant

    public final String getThemeConstant(String constantName, String def)

    Returns a theme constant defined in the resource editor

    ###### Parameters

    - `constantName`: the name of the constant

    - `def`: default value

    ###### Returns

    the value of the constant or the default if the constant isn't in the theme

  - ### isThemeConstant

    public final boolean isThemeConstant(String constantName, boolean def)

    Returns a theme constant defined in the resource editor as a boolean value

    ###### Parameters

    - `constantName`: the name of the constant

    - `def`: default value

    ###### Returns

    the value of the constant or the default if the constant isn't in the theme

  - ### isThemeConstant

    public Boolean isThemeConstant(String constantName)

    Returns a theme constant defined in the resource editor as a boolean value or null if the constant isn't defined

    ###### Parameters

    - `constantName`: the name of the constant

    ###### Returns

    the value of the constant or null if the constant isn't in the theme

  - ### getThemeImageConstant

    public Image getThemeImageConstant(String constantName)

    Returns a theme constant defined in the resource editor

    ###### Parameters

    - `constantName`: the name of the constant

    ###### Returns

    the image if defined

  - ### getThemeMaskConstant

    public Object getThemeMaskConstant(String constantName)

    Returns a theme mask constant

    ###### Parameters

    - `constantName`: the name of the constant

    ###### Returns

    the mask if defined

  - ### getResourceBundle

    public Hashtable getResourceBundle()

    The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.

    ###### Returns

    the localization bundle

    ###### Deprecated

    this method uses the old resource bundle hashtable, use the new getBundle() method

  - ### setResourceBundle

    public void setResourceBundle(Hashtable resourceBundle)

    The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.

    ###### Parameters

    - `resourceBundle`: the localization bundle

    ###### Deprecated

    this method uses the old resource bundle hashtable, use the new setBundle() method

  - ### getBundle

    public Map<String,String> getBundle()

    The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.

    ###### Returns

    the localization bundle

  - ### setBundle

    public void setBundle(Map<String,String> bundle)

    The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.

    ###### Parameters

    - `resourceBundle`: the localization bundle

  - ### localize

    public final String localize(String key, String defaultValue)

    Localizes the given string from the resource bundle if such a String exists in the resource bundle. If no key exists in the bundle then or a bundle is not installed the default value is returned.

    ###### Parameters

    - `key`: The key used to lookup in the resource bundle

    - `defaultValue`: the value returned if no such key exists

    ###### Returns

    either default value or the appropriate value

  - ### onLocalize

    protected void onLocalize(String key, String defaultValue)

    Callback for subclasses that wish to track localization invocations.

    ###### Parameters

    - `key`: The key used to lookup in the resource bundle

    - `defaultValue`: the value returned if no such key exists

  - ### addThemeRefreshListener

    public void addThemeRefreshListener(ActionListener l)

    Adds a Theme refresh listener. The listenres will get a callback when setThemeProps method is invoked.

    ###### Parameters

    - `l`: an ActionListener to be added

  - ### removeThemeRefreshListener

    public void removeThemeRefreshListener(ActionListener l)

    Removes a Theme refresh listener.

    ###### Parameters

    - `l`: an ActionListener to be removed