Class DynamicStyle

  • All Implemented Interfaces:

    @API(since = "5.3", status = API.Status.EXPERIMENTAL) 
    public class DynamicStyle
    
                        

    By default, Swing does not provide a way to augment components when look and feel changes. There's updateUI, however, it requires to sub-class component class.

    DynamicStyle enables to augment the components (e.g. border, font, color) as LaF changes

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      DynamicStyle()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      <T extends JComponent> T withDynamic(T component, Consumer<in T> onUpdateUi) Attaches a configuration action that is executed when Look and Feel changes.
      <T extends JComponent> T withBorder(T component, String resource)
      <T extends JComponent> T withFont(T component, String resource)
      static Closeable onLaFChange(Runnable action) Schedules an action to be executed after each Look and Feel change.
      void updateLaf() Re-initializes the current LaF and updates the UI for all the open windows.
      void updateLaf(String className) Set new look and feel for all the open windows.
      void updateComponentTreeUI(Component root) Updates UI for the components under a given component.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DynamicStyle

        DynamicStyle()
    • Method Detail

      • withDynamic

        @API(since = "5.3", status = API.Status.EXPERIMENTAL) <T extends JComponent> T withDynamic(T component, Consumer<in T> onUpdateUi)

        Attaches a configuration action that is executed when Look and Feel changes.

        Note: the action is executed when withDynamic is called, and the action is executed even if the new and the old LaFs are the same.

        Parameters:
        component - component to update
        onUpdateUi - action to run (immediately and when look and feel changes)
        Returns:

        input component (e.g. for fluent APIs)

      • withFont

        @API(since = "5.3", status = API.Status.EXPERIMENTAL) <T extends JComponent> T withFont(T component, String resource)
      • onLaFChange

        @API(since = "5.3", status = API.Status.EXPERIMENTAL) static Closeable onLaFChange(Runnable action)

        Schedules an action to be executed after each Look and Feel change.

        Parameters:
        action - action to execute
        Returns:

        a handle that can be used to un-register the listener

      • updateLaf

        @API(since = "5.3", status = API.Status.EXPERIMENTAL) void updateLaf()

        Re-initializes the current LaF and updates the UI for all the open windows.

      • updateLaf

        @API(since = "5.3", status = API.Status.EXPERIMENTAL) void updateLaf(String className)

        Set new look and feel for all the open windows.

        Parameters:
        className - look and feel class name
      • updateComponentTreeUI

        @API(since = "5.3", status = API.Status.EXPERIMENTAL) void updateComponentTreeUI(Component root)

        Updates UI for the components under a given component.

        Parameters:
        root - the root of the hierarchy to update