Package swingtree

Class ComponentMouseEventDelegate<C extends JComponent>

java.lang.Object
swingtree.ComponentDelegate<C,MouseEvent>
swingtree.ComponentMouseEventDelegate<C>
Direct Known Subclasses:
ComponentDragEventDelegate, TabDelegate

public class ComponentMouseEventDelegate<C extends JComponent> extends ComponentDelegate<C,MouseEvent>
A JComponent as well as MouseEvent delegate providing useful context information to various Action listeners which are typically registered through UIForAnySwing.onMouseClick(sprouts.Action)}, UIForAnySwing.onMousePress(sprouts.Action) and UIForAnySwing.onMouseRelease(sprouts.Action), among others.
This delegate is designed to provide clutter-free access to both the concrete JComponent subtype C as well a the MouseEvent which triggered the action.

Here is an example of how this delegate is typically exposed in your Action:


  UI.panel()
  .onMouseMove( it -> {
    System.out.println("Moved on " + it.get());
    System.out.println("Moved at " + it.mouseX() + ", " + it.mouseY());
  })
  .onMouseClick( it -> {
    System.out.println("Clicked on " + it.get());
    System.out.println("Click count: " + it.clickCount());
  })
  //...
  

For some more examples please take a look at the living swing-tree documentation.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected C
     
    protected final boolean
     
    protected final boolean
     
    protected List<JComponent>
     
    final Animator
    animateFor(double duration, TimeUnit unit)
    Exposes access the animation builder API, where you can define the conditions under which the animation should be executed and then dispatch the animation to the EDT through the Animator.go(Animation) method.
    final void
    animateFor(double duration, TimeUnit unit, Animation animation)
    Use this to schedule and run the provided animation to be executed on the EDT.
    final Animator
    animateFor(LifeTime lifeTime)
    Exposes access the animation builder API, where you can define the conditions under which the animation should be executed and then dispatch the animation to the EDT through the Animator.go(Animation) method.
    final void
    animateFor(LifeTime lifeTime, Animation animation)
    Use this to schedule and run the provided animation to be executed on the EDT.
    final void
    animateStyleFor(double duration, TimeUnit unit, AnimatedStyler<C> styler)
    A common use case is to animate the style of a component when a user event occurs.
    final void
    A common use case is to animate the style of a component when a user event occurs.
    int
    Returns the number of mouse clicks associated with the event of this delegate.
    final <T extends JComponent>
    OptionalUI<T>
    find(Class<T> type, Enum<?> id)
    Use this to query the UI tree and find any JComponent of a particular type and id (the name of the component).
    final <T extends JComponent>
    OptionalUI<T>
    find(Class<T> type, String id)
    Use this to query the UI tree and find any JComponent of a particular type and id (the name of the component).
    final <T extends JComponent>
    OptionalUI<T>
    find(Class<T> type, Predicate<T> predicate)
    Use this to query the UI tree and find any JComponent based on a specific type and a predicate which is used to test if a particular component in the tree is the one you are looking for.
    final <T extends JComponent>
    List<T>
    findAll(Class<T> type, Predicate<T> predicate)
    Use this to query the UI tree and find all JComponents based on a specific type and a predicate which is used to test if a particular component in the tree is the one you are looking for.
    final <T extends JComponent>
    List<T>
    findAllByGroup(Class<T> type, Enum<?> group)
    Use this to query the UI tree and find all JComponents of a particular type and also that belong to a particular style group.
    final <T extends JComponent>
    List<T>
    findAllByGroup(Class<T> type, String group)
    Use this to query the UI tree and find all JComponents of a particular type and also that belong to a particular style group.
    findAllByGroup(Enum<?> group)
    Use this to query the UI tree and find all JComponents that belong to a particular style group.
    Use this to query the UI tree and find all JComponents that belong to a particular style group.
    final C
    get()
    This is a delegate to the underlying component, but not every method of the component is delegated.
    final Color
    As a delegate to the underlying component, you can use this method to conveniently get the background color of the component.
    final Border
    As a delegate to the underlying component, you can use this method to conveniently get the border of the component.
    final Rectangle
    As a delegate to the underlying component, you can use this method to conveniently get the bounds of the component.
    final Cursor
    As a delegate to the underlying component, you can use this method to conveniently get the Cursor of the component.
    final Font
    As a delegate to the underlying component, you can use this method to conveniently get the font of the component.
    final Color
    As a delegate to the underlying component, you can use this method to conveniently get the foreground color of the component.
    final int
    As a delegate to the underlying component, you can use this method to conveniently get the height of the component.
    final Point
    As a delegate to the underlying component, you can use this method to conveniently access the location of the component relative to its parent in the form of a Point object.
    final Size
    As a delegate to the underlying component, you can use this method to conveniently get the maximum size of the component.
    final Size
    As a delegate to the underlying component, you can use this method to conveniently get the minimum size of the component.
    final Container
    This is class a delegate API, which means that it represents the API of a wrapped component.
    final Size
    As a delegate to the underlying component, you can use this method to conveniently get the preferred size of the component.
    float
    The number returned by this method is used to scale the UI to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
    final Size
    As a delegate to the underlying component, you can use this method to conveniently get the size of the component.
    final String
    As a delegate to the underlying component, you can use this method to conveniently get the tooltip of the component.
    final int
    As a delegate to the underlying component, you can use this method to conveniently get the width of the component.
    final int
    As a delegate to the underlying component, you can use this method to conveniently access the x-coordinate of the component relative to its parent.
    final int
    As a delegate to the underlying component, you can use this method to conveniently access the y-coordinate of the component relative to its parent.
    boolean
    Returns whether the Alt modifier is down on the event of this delegate.
    boolean
    Returns whether the Control modifier is down on the event of this delegate.
    final boolean
    As a delegate to the underlying component, you can use this method to conveniently check if the component is enabled.
    boolean
    Returns true if the mouse event of this delegate is the left mouse button.
    boolean
    Returns whether the Meta modifier is down on the event of this delegate.
    boolean
    Returns true if the mouse event of this delegate is the middle mouse button.
    final boolean
    As a delegate to the underlying component, you can use this method to conveniently check if the component is opaque.
    boolean
    Returns true if the mouse event of this delegate is the right mouse button.
    boolean
    Returns whether the Shift modifier is down on the event of this delegate.
    final boolean
    As a delegate to the underlying component, you can use this method to conveniently check if the component is visible.
    int
    Returns the x coordinate of the mouse event of this delegate.
    int
    Returns the absolute horizontal x position of the event of this delegate.
    int
    Returns the y coordinate of the mouse event of this delegate.
    int
    Returns the absolute vertical y position of the event of this delegate.
    final void
    paint(AnimationState state, Painter painter)
    A common use case is to render something on top of the component using the Graphics2D instance of the component.
    final void
    paint(UI.ComponentArea area, AnimationState state, Painter painter)
    A common use case is to render something on top of the component using the Graphics2D instance of the component.
    float
    The number returned by this method is used to scale the UI to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
    double
    scale(double value)
    Use this method inside custom Painter implementations (see paint(AnimationState, Painter)) to scale a double value by the current UI scale factor to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
    float
    scale(float value)
    Use this method inside custom Painter implementations (see paint(AnimationState, Painter)) to scale a float value by the current UI scale factor to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
    int
    scale(int value)
    Use this method inside custom Painter implementations (see paint(AnimationState, Painter)) to scale an int value by the current UI scale factor to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the background color of the component.
    final swingtree.AbstractDelegate<C>
    setBackgroundColor(double r, double g, double b)
    As a delegate to the underlying component, you can use this method to conveniently set the background color of the component.
    final swingtree.AbstractDelegate<C>
    setBackgroundColor(double r, double g, double b, double a)
    As a delegate to the underlying component, you can use this method to conveniently set the background color of the component.
    final swingtree.AbstractDelegate<C>
    setBackgroundColor(int r, int g, int b)
    As a delegate to the underlying component, you can use this method to conveniently set the background color of the component.
    final swingtree.AbstractDelegate<C>
    setBackgroundColor(int r, int g, int b, int a)
    As a delegate to the underlying component, you can use this method to conveniently set the background color of the component.
    final swingtree.AbstractDelegate<C>
    setBorder(Border border)
    As a delegate to the underlying component, you can use this method to conveniently set the border of the component.
    final swingtree.AbstractDelegate<C>
    setBounds(int x, int y, int width, int height)
    As a delegate to the underlying component, you can use this method to conveniently set the bounds of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the bounds of the component.
    final swingtree.AbstractDelegate<C>
    setBounds(Bounds bounds)
    Delegates to the Component.setBounds(int, int, int, int) method of the underlying component.
    final swingtree.AbstractDelegate<C>
    setCursor(Cursor cursor)
    As a delegate to the underlying component, you can use this method to conveniently set the Cursor of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the UI.Cursor of the component.
    final swingtree.AbstractDelegate<C>
    setEnabled(boolean enabled)
    As a delegate to the underlying component, you can use this method to conveniently enable or disable the component.
    final swingtree.AbstractDelegate<C>
    setFont(Font font)
    As a delegate to the underlying component, you can use this method to conveniently set the font of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component.
    final swingtree.AbstractDelegate<C>
    setForegroundColor(double r, double g, double b)
    As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component.
    final swingtree.AbstractDelegate<C>
    setForegroundColor(double r, double g, double b, double a)
    As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component.
    final swingtree.AbstractDelegate<C>
    setForegroundColor(int r, int g, int b)
    As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component.
    final swingtree.AbstractDelegate<C>
    setForegroundColor(int r, int g, int b, int a)
    As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component.
    final swingtree.AbstractDelegate<C>
    setHeight(int height)
    As a delegate to the underlying component, you can use this method to conveniently set the height of the component.
    final swingtree.AbstractDelegate<C>
    setMaxHeight(int height)
    As a delegate to the underlying component, you can use this method to conveniently set the maximum height of the component.
    final swingtree.AbstractDelegate<C>
    setMaxSize(int width, int height)
    As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component.
    final swingtree.AbstractDelegate<C>
    setMaxWidth(int width)
    As a delegate to the underlying component, you can use this method to conveniently set the maximum width of the component.
    final swingtree.AbstractDelegate<C>
    setMinHeight(int height)
    As a delegate to the underlying component, you can use this method to conveniently set the minimum height of the component.
    final swingtree.AbstractDelegate<C>
    setMinSize(int width, int height)
    As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component.
    final swingtree.AbstractDelegate<C>
    setMinWidth(int width)
    As a delegate to the underlying component, you can use this method to conveniently set the minimum width of the component.
    final swingtree.AbstractDelegate<C>
    setOpaque(boolean opaque)
    As a delegate to the underlying component, you can use this method to conveniently make the component opaque or transparent.
    final swingtree.AbstractDelegate<C>
    setPrefHeight(int height)
    As a delegate to the underlying component, you can use this method to conveniently set the preferred height of the component.
    final swingtree.AbstractDelegate<C>
    setPrefSize(int width, int height)
    As a delegate to the underlying component, you can use this method to conveniently set the preferred size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the preferred size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the preferred size of the component.
    final swingtree.AbstractDelegate<C>
    setPrefWidth(int width)
    As a delegate to the underlying component, you can use this method to conveniently set the preferred width of the component.
    final swingtree.AbstractDelegate<C>
    setSize(int width, int height)
    As a delegate to the underlying component, you can use this method to conveniently set the size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the size of the component.
    final swingtree.AbstractDelegate<C>
    setSize(Size size)
    As a delegate to the underlying component, you can use this method to conveniently set the size of the component.
    final swingtree.AbstractDelegate<C>
    As a delegate to the underlying component, you can use this method to conveniently set the tooltip of the component.
    final swingtree.AbstractDelegate<C>
    setVisible(boolean visible)
    As a delegate to the underlying component, you can use this method to conveniently enable or disable the component.
    final swingtree.AbstractDelegate<C>
    setWidth(int width)
    As a delegate to the underlying component, you can use this method to conveniently set the width of the component.
    final void
    style(AnimationState state, Styler<C> styler)
    A common use case is to style the component based on the current animation state.

    Methods inherited from class java.lang.Object

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

    • ComponentMouseEventDelegate

      public ComponentMouseEventDelegate(C component, MouseEvent event)
  • Method Details

    • isLeftMouseButton

      public boolean isLeftMouseButton()
      Returns true if the mouse event of this delegate is the left mouse button.
      Returns:
      true if the left mouse button was active
    • isRightMouseButton

      public boolean isRightMouseButton()
      Returns true if the mouse event of this delegate is the right mouse button.
      Returns:
      true if the right mouse button was active
    • isMiddleMouseButton

      public boolean isMiddleMouseButton()
      Returns true if the mouse event of this delegate is the middle mouse button.
      Returns:
      true if the middle mouse button was active
    • isAltDown

      public boolean isAltDown()
      Returns whether the Alt modifier is down on the event of this delegate.
      Returns:
      true if the alt modifier is down
    • isCtrlDown

      public boolean isCtrlDown()
      Returns whether the Control modifier is down on the event of this delegate.
      Returns:
      true if the control modifier is down
    • isShiftDown

      public boolean isShiftDown()
      Returns whether the Shift modifier is down on the event of this delegate.
      Returns:
      true if the shift modifier is down
    • isMetaDown

      public boolean isMetaDown()
      Returns whether the Meta modifier is down on the event of this delegate.
      Returns:
      true if the meta modifier is down
    • clickCount

      public int clickCount()
      Returns the number of mouse clicks associated with the event of this delegate. You can use the returned number to distinguish between single-click and double-click events.
      Returns:
      An integer indicating the number of mouse clicks associated with the mouse event.
    • mouseX

      public int mouseX()
      Returns the x coordinate of the mouse event of this delegate.
      Returns:
      integer value for the x coordinate
    • mouseY

      public int mouseY()
      Returns the y coordinate of the mouse event of this delegate.
      Returns:
      integer value for the y coordinate
    • mouseXOnScreen

      public int mouseXOnScreen()
      Returns the absolute horizontal x position of the event of this delegate. In a virtual device multi-screen environment in which the desktop area could span multiple physical screen devices, this coordinate is relative to the virtual coordinate system. Otherwise, this coordinate is relative to the coordinate system associated with the Component's GraphicsConfiguration.
      Returns:
      x an integer indicating absolute horizontal position.
    • mouseYOnScreen

      public int mouseYOnScreen()
      Returns the absolute vertical y position of the event of this delegate. In a virtual device multiscreen environment in which the desktop area could span multiple physical screen devices, this coordinate is relative to the virtual coordinate system. Otherwise, this coordinate is relative to the coordinate system associated with the Component's GraphicsConfiguration.
      Returns:
      y an integer indicating absolute vertical position.
    • _isUndefinedFont

      protected final boolean _isUndefinedFont(Font font)
    • _isUndefinedColor

      protected final boolean _isUndefinedColor(Color color)
    • _component

      protected C _component()
    • _siblingsSource

      protected List<JComponent> _siblingsSource()
    • get

      public final C get()
      This is a delegate to the underlying component, but not every method of the component is delegated. This method allows you to access the underlying component directly.

      Note that this method expects that the accessing thread is the event dispatch thread, not the application thread. If you want to access the component from the application thread, you should use
      UI.run(() -> delegate.component()).

      Returns:
      The underlying component.
      Throws:
      IllegalStateException - If the accessing thread is not the event dispatch thread.
    • getX

      public final int getX()
      As a delegate to the underlying component, you can use this method to conveniently access the x-coordinate of the component relative to its parent.
      Returns:
      The x-coordinate of the component relative to its parent.
    • getY

      public final int getY()
      As a delegate to the underlying component, you can use this method to conveniently access the y-coordinate of the component relative to its parent.
      Returns:
      The y-coordinate of the component relative to its parent.
    • getLocation

      public final Point getLocation()
      As a delegate to the underlying component, you can use this method to conveniently access the location of the component relative to its parent in the form of a Point object. The value returned by this method is equal to the value returned by getX() and getY().
      Returns:
      The location of the component relative to its parent.
    • getParent

      public final Container getParent()
      This is class a delegate API, which means that it represents the API of a wrapped component. This method allows you to access the parent of the underlying component. In essence, this is a delegate to Component.getParent().
      Returns:
      The parent Container of the underlying component.
      Throws:
      IllegalStateException - If the accessing thread is not the event dispatch thread.
    • setBackground

      public final swingtree.AbstractDelegate<C> setBackground(Color color)
      As a delegate to the underlying component, you can use this method to conveniently set the background color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBackground(Color) for more information.

      Parameters:
      color - The color that should be used to paint the background of the component. If this parameter is null then this component will inherit the background color of its parent.
      Returns:
      The delegate itself.
    • setBackgroundColor

      public final swingtree.AbstractDelegate<C> setBackgroundColor(double r, double g, double b)
      As a delegate to the underlying component, you can use this method to conveniently set the background color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBackground(Color) for more information.

      Parameters:
      r - The red component of the color as a double between 0 and 1.
      g - The green component of the color as a double between 0 and 1.
      b - The blue component of the color as a double between 0 and 1.
      Returns:
      The delegate itself.
    • setBackgroundColor

      public final swingtree.AbstractDelegate<C> setBackgroundColor(double r, double g, double b, double a)
      As a delegate to the underlying component, you can use this method to conveniently set the background color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBackground(Color) for more information.

      Parameters:
      r - The red component of the color as a double between 0 and 1.
      g - The green component of the color as a double between 0 and 1.
      b - The blue component of the color as a double between 0 and 1.
      a - The alpha component of the color as a double between 0 and 1.
      Returns:
      The delegate itself.
    • setBackgroundColor

      public final swingtree.AbstractDelegate<C> setBackgroundColor(int r, int g, int b)
      As a delegate to the underlying component, you can use this method to conveniently set the background color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBackground(Color) for more information.

      Parameters:
      r - The red component of the color as an integer between 0 and 255.
      g - The green component of the color as an integer between 0 and 255.
      b - The blue component of the color as an integer between 0 and 255.
      Returns:
      The delegate itself.
    • setBackgroundColor

      public final swingtree.AbstractDelegate<C> setBackgroundColor(int r, int g, int b, int a)
      As a delegate to the underlying component, you can use this method to conveniently set the background color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBackground(Color) for more information.

      Parameters:
      r - The red component of the color as an integer between 0 and 255.
      g - The green component of the color as an integer between 0 and 255.
      b - The blue component of the color as an integer between 0 and 255.
      a - The alpha component of the color as an integer between 0 and 255.
      Returns:
      The delegate itself.
    • getBackground

      public final Color getBackground()
      As a delegate to the underlying component, you can use this method to conveniently get the background color of the component.

      See Component.getBackground() for more information.

      Returns:
      The background color of the component, or UI.Color.UNDEFINED if the component does not have a background color (i.e. Component.getBackground() returns null). The return value will never be null.
    • setForeground

      public final swingtree.AbstractDelegate<C> setForeground(Color color)
      As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setForeground(Color) for more information.

      Parameters:
      color - The color that should be used to paint the foreground of the component. If this parameter is null then this component will inherit the foreground color of its parent.
      Returns:
      The delegate itself.
    • getForeground

      public final Color getForeground()
      As a delegate to the underlying component, you can use this method to conveniently get the foreground color of the component.

      See Component.getForeground() for more information.

      Returns:
      The foreground color of the component, or UI.Color.UNDEFINED if the component does not have a foreground color (i.e. Component.getForeground() returns null). The return value will never be null.
    • setForegroundColor

      public final swingtree.AbstractDelegate<C> setForegroundColor(double r, double g, double b)
      As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setForeground(Color) for more information.

      Parameters:
      r - The red component of the color as a double between 0 and 1.
      g - The green component of the color as a double between 0 and 1.
      b - The blue component of the color as a double between 0 and 1.
      Returns:
      The delegate itself.
    • setForegroundColor

      public final swingtree.AbstractDelegate<C> setForegroundColor(double r, double g, double b, double a)
      As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setForeground(Color) for more information.

      Parameters:
      r - The red component of the color as a double between 0 and 1.
      g - The green component of the color as a double between 0 and 1.
      b - The blue component of the color as a double between 0 and 1.
      a - The alpha component of the color as a double between 0 and 1.
      Returns:
      The delegate itself.
    • setForegroundColor

      public final swingtree.AbstractDelegate<C> setForegroundColor(int r, int g, int b)
      As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setForeground(Color) for more information.

      Parameters:
      r - The red component of the color as an integer between 0 and 255.
      g - The green component of the color as an integer between 0 and 255.
      b - The blue component of the color as an integer between 0 and 255.
      Returns:
      The delegate itself.
    • setForegroundColor

      public final swingtree.AbstractDelegate<C> setForegroundColor(int r, int g, int b, int a)
      As a delegate to the underlying component, you can use this method to conveniently set the foreground color of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setForeground(Color) for more information.

      Parameters:
      r - The red component of the color as an integer between 0 and 255.
      g - The green component of the color as an integer between 0 and 255.
      b - The blue component of the color as an integer between 0 and 255.
      a - The alpha component of the color as an integer between 0 and 255.
      Returns:
      The delegate itself.
    • setFont

      public final swingtree.AbstractDelegate<C> setFont(Font font)
      As a delegate to the underlying component, you can use this method to conveniently set the font of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setFont(Font) for more information.

      Parameters:
      font - The font that should be used to paint the text of the component. If this parameter is UI.Font.UNDEFINED then this component will inherit the font of its parent. Null is not allowed.
      Returns:
      The delegate itself.
    • getFont

      public final Font getFont()
      As a delegate to the underlying component, you can use this method to conveniently get the font of the component.

      See Component.getFont() for more information.

      Returns:
      The font of the component.
    • setBorder

      public final swingtree.AbstractDelegate<C> setBorder(Border border)
      As a delegate to the underlying component, you can use this method to conveniently set the border of the component. This method returns the delegate itself, so you can chain calls to this method.

      Note that this method is a delegate to JComponent.setBorder(Border).

      Parameters:
      border - The border that should be used to paint the border of the component. If this parameter is null then this component will inherit the border of its parent.
      Returns:
      The delegate itself.
    • getBorder

      public final Border getBorder()
      As a delegate to the underlying component, you can use this method to conveniently get the border of the component.

      Note that this method is a delegate to JComponent.getBorder().

      Returns:
      The border of the component.
    • setBounds

      public final swingtree.AbstractDelegate<C> setBounds(int x, int y, int width, int height)
      As a delegate to the underlying component, you can use this method to conveniently set the bounds of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBounds(int, int, int, int) for more information.

      Parameters:
      x - The x coordinate of the new location of the component. This is relative to the component's parent.
      y - The y coordinate of the new location of the component. This is relative to the component's parent.
      width - The new width of the component.
      height - The new height of the component.
      Returns:
      The delegate itself, so you can chain calls to this method.
    • setBounds

      public final swingtree.AbstractDelegate<C> setBounds(Bounds bounds)
      Delegates to the Component.setBounds(int, int, int, int) method of the underlying component. The bounds consist of a location and a size which are relative to the component's parent.
      Parameters:
      bounds - The new bounds of the component. This is relative to the component's parent.
      Returns:
      The delegate itself, so you can chain calls to this method.
    • setBounds

      public final swingtree.AbstractDelegate<C> setBounds(Rectangle bounds)
      As a delegate to the underlying component, you can use this method to conveniently set the bounds of the component. This method returns the delegate itself, so you can chain calls to this method.

      See Component.setBounds(Rectangle) for more information.

      Parameters:
      bounds - The new bounds of the component. This is relative to the component's parent.
      Returns:
      The delegate itself, so you can chain calls to this method.
    • getBounds

      public final Rectangle getBounds()
      As a delegate to the underlying component, you can use this method to conveniently get the bounds of the component.

      See Component.getBounds() for more information.

      Returns:
      The bounds of the component. This is relative to the component's parent.
    • setPrefSize

      public final swingtree.AbstractDelegate<C> setPrefSize(Dimension size)
      As a delegate to the underlying component, you can use this method to conveniently set the preferred size of the component. This method returns the delegate itself, so you can chain calls to this method. The preferred size is used by the layout manager to determine the size of the component.

      See Component.setPreferredSize(Dimension) for more information.

      Parameters:
      size - The preferred size of the component.
      Returns:
      The delegate itself.
    • setPrefSize

      public final swingtree.AbstractDelegate<C> setPrefSize(Size size)
      As a delegate to the underlying component, you can use this method to conveniently set the preferred size of the component. This method returns the delegate itself, so you can chain calls to this method. The preferred size is used by the layout manager to determine the size of the component.

      See Component.setPreferredSize(Dimension) for more information.

      Parameters:
      size - The preferred size of the component.
      Returns:
      The delegate itself.
    • setPrefSize

      public final swingtree.AbstractDelegate<C> setPrefSize(int width, int height)
      As a delegate to the underlying component, you can use this method to conveniently set the preferred size of the component. This method returns the delegate itself, so you can chain calls to this method. The preferred size is used by the layout manager to determine the size of the component.

      See Component.setPreferredSize(Dimension) for more information.

      Parameters:
      width - The preferred width of the component.
      height - The preferred height of the component.
      Returns:
      The delegate itself.
    • setPrefWidth

      public final swingtree.AbstractDelegate<C> setPrefWidth(int width)
      As a delegate to the underlying component, you can use this method to conveniently set the preferred width of the component. This method returns the delegate itself, so you can chain calls to this method. The preferred size is used by the layout manager to determine the size of the component.

      See Component.setPreferredSize(Dimension) for more information.

      Parameters:
      width - The preferred width of the component.
      Returns:
      The delegate itself.
    • setPrefHeight

      public final swingtree.AbstractDelegate<C> setPrefHeight(int height)
      As a delegate to the underlying component, you can use this method to conveniently set the preferred height of the component. This method returns the delegate itself, so you can chain calls to this method. The preferred size is used by the layout manager to determine the size of the component.

      See Component.setPreferredSize(Dimension) for more information.

      Parameters:
      height - The preferred height of the component.
      Returns:
      The delegate itself.
    • getPrefSize

      public final Size getPrefSize()
      As a delegate to the underlying component, you can use this method to conveniently get the preferred size of the component. The preferred size is used by the layout manager to determine the size of the component.

      See Component.getPreferredSize() for more information.

      Returns:
      The preferred size of the component.
    • setMinSize

      public final swingtree.AbstractDelegate<C> setMinSize(Dimension size)
      As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component. This method returns the delegate itself, so you can chain calls to this method. The minimum size is used by the layout manager to determine the size of the component.

      See Component.setMinimumSize(Dimension) for more information.

      Parameters:
      size - The minimum size of the component.
      Returns:
      The delegate itself.
    • setMinSize

      public final swingtree.AbstractDelegate<C> setMinSize(Size size)
      As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component. This method returns the delegate itself, so you can chain calls to this method. The minimum size is used by the layout manager to determine the size of the component.

      See Component.setMinimumSize(Dimension) for more information.

      Parameters:
      size - The minimum size of the component.
      Returns:
      The delegate itself.
    • setMinSize

      public final swingtree.AbstractDelegate<C> setMinSize(int width, int height)
      As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component. This method returns the delegate itself, so you can chain calls to this method. The minimum size is used by the layout manager to determine the size of the component.

      See Component.setMinimumSize(Dimension) for more information.

      Parameters:
      width - The minimum width of the component.
      height - The minimum height of the component.
      Returns:
      The delegate itself.
    • setMinWidth

      public final swingtree.AbstractDelegate<C> setMinWidth(int width)
      As a delegate to the underlying component, you can use this method to conveniently set the minimum width of the component. This method returns the delegate itself, so you can chain calls to this method. The minimum size is used by the layout manager to determine the size of the component.

      See Component.setMinimumSize(Dimension) for more information.

      Parameters:
      width - The minimum width of the component.
      Returns:
      The delegate itself.
    • setMinHeight

      public final swingtree.AbstractDelegate<C> setMinHeight(int height)
      As a delegate to the underlying component, you can use this method to conveniently set the minimum height of the component. This method returns the delegate itself, so you can chain calls to this method. The minimum size is used by the layout manager to determine the size of the component.

      See Component.setMinimumSize(Dimension) for more information.

      Parameters:
      height - The minimum height of the component.
      Returns:
      The delegate itself.
    • getMinSize

      public final Size getMinSize()
      As a delegate to the underlying component, you can use this method to conveniently get the minimum size of the component. The minimum size is used by the layout manager to determine the size of the component.

      See Component.getMinimumSize() for more information.

      Returns:
      The minimum size of the component.
    • setMaxSize

      public final swingtree.AbstractDelegate<C> setMaxSize(Dimension size)
      As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component. This method returns the delegate itself, so you can chain calls to this method. The maximum size is used by the layout manager to determine the size of the component.

      See Component.setMaximumSize(Dimension) for more information.

      Parameters:
      size - The maximum size of the component.
      Returns:
      The delegate itself.
    • setMaxSize

      public final swingtree.AbstractDelegate<C> setMaxSize(Size size)
      As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component. This method returns the delegate itself, so you can chain calls to this method. The maximum size is used by the layout manager to determine the size of the component.

      See Component.setMaximumSize(Dimension) for more information.

      Parameters:
      size - The maximum size of the component.
      Returns:
      The delegate itself.
    • setMaxSize

      public final swingtree.AbstractDelegate<C> setMaxSize(int width, int height)
      As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component. This method returns the delegate itself, so you can chain calls to this method. The maximum size is used by the layout manager to determine the size of the component.

      See Component.setMaximumSize(Dimension) for more information.

      Parameters:
      width - The maximum width of the component.
      height - The maximum height of the component.
      Returns:
      The delegate itself.
    • setMaxWidth

      public final swingtree.AbstractDelegate<C> setMaxWidth(int width)
      As a delegate to the underlying component, you can use this method to conveniently set the maximum width of the component. This method returns the delegate itself, so you can chain calls to this method. The maximum size is used by the layout manager to determine the size of the component.

      See Component.setMaximumSize(Dimension) for more information.

      Parameters:
      width - The maximum width of the component.
      Returns:
      The delegate itself.
    • setMaxHeight

      public final swingtree.AbstractDelegate<C> setMaxHeight(int height)
      As a delegate to the underlying component, you can use this method to conveniently set the maximum height of the component. This method returns the delegate itself, so you can chain calls to this method. The maximum size is used by the layout manager to determine the size of the component.

      See Component.setMaximumSize(Dimension) for more information.

      Parameters:
      height - The maximum height of the component.
      Returns:
      The delegate itself.
    • getMaxSize

      public final Size getMaxSize()
      As a delegate to the underlying component, you can use this method to conveniently get the maximum size of the component. The maximum size is used by the layout manager to determine the size of the component.

      See Component.getMaximumSize() for more information.

      Returns:
      The maximum size of the component.
    • setSize

      public final swingtree.AbstractDelegate<C> setSize(Dimension size)
      As a delegate to the underlying component, you can use this method to conveniently set the size of the component. This method returns the delegate itself, so you can chain calls to this method. The size is used by the layout manager to determine the size of the component.

      See Component.setSize(Dimension) for more information.

      Parameters:
      size - The size of the component.
      Returns:
      The delegate itself.
    • setSize

      public final swingtree.AbstractDelegate<C> setSize(Size size)
      As a delegate to the underlying component, you can use this method to conveniently set the size of the component. This method returns the delegate itself, so you can chain calls to this method. The size is used by the layout manager to determine the size of the component.

      See Component.setSize(Dimension) for more information.

      Parameters:
      size - The size of the component.
      Returns:
      The delegate itself.
    • setSize

      public final swingtree.AbstractDelegate<C> setSize(int width, int height)
      As a delegate to the underlying component, you can use this method to conveniently set the size of the component. This method returns the delegate itself, so you can chain calls to this method. The size is used by the layout manager to determine the size of the component.

      See Component.setSize(Dimension) for more information.

      Parameters:
      width - The width of the component.
      height - The height of the component.
      Returns:
      The delegate itself.
    • setWidth

      public final swingtree.AbstractDelegate<C> setWidth(int width)
      As a delegate to the underlying component, you can use this method to conveniently set the width of the component. This method returns the delegate itself, so you can chain calls to this method. The size is used by the layout manager to determine the size of the component.

      See Component.setSize(Dimension) for more information.

      Parameters:
      width - The width of the component.
      Returns:
      The delegate itself.
    • setHeight

      public final swingtree.AbstractDelegate<C> setHeight(int height)
      As a delegate to the underlying component, you can use this method to conveniently set the height of the component. This method returns the delegate itself, so you can chain calls to this method. The size is used by the layout manager to determine the size of the component.

      See Component.setSize(Dimension) for more information.

      Parameters:
      height - The height of the component.
      Returns:
      The delegate itself.
    • getSize

      public final Size getSize()
      As a delegate to the underlying component, you can use this method to conveniently get the size of the component. The size is used by the layout manager to determine the size of the component.

      See Component.getSize() for more information.

      Returns:
      The size of the component.
    • getWidth

      public final int getWidth()
      As a delegate to the underlying component, you can use this method to conveniently get the width of the component. The size is used by the layout manager to determine the size of the component.

      See Component.getSize() for more information.

      Returns:
      The width of the component.
    • getHeight

      public final int getHeight()
      As a delegate to the underlying component, you can use this method to conveniently get the height of the component. The size is used by the layout manager to determine the size of the component.

      See Component.getSize() for more information.

      Returns:
      The height of the component.
    • setCursor

      public final swingtree.AbstractDelegate<C> setCursor(UI.Cursor cursor)
      As a delegate to the underlying component, you can use this method to conveniently set the UI.Cursor of the component.
      Parameters:
      cursor - The UI.Cursor which should be set.
      Returns:
      The delegate itself.
    • setCursor

      public final swingtree.AbstractDelegate<C> setCursor(Cursor cursor)
      As a delegate to the underlying component, you can use this method to conveniently set the Cursor of the component.
      Parameters:
      cursor - The Cursor which should be set.
      Returns:
      The delegate itself.
    • getCursor

      public final Cursor getCursor()
      As a delegate to the underlying component, you can use this method to conveniently get the Cursor of the component.
      Returns:
      The Cursor of the component.
    • setTooltip

      public final swingtree.AbstractDelegate<C> setTooltip(String text)
      As a delegate to the underlying component, you can use this method to conveniently set the tooltip of the component. This method returns the delegate itself, so you can chain calls to this method.

      See JComponent.setToolTipText(String) for more information.

      Parameters:
      text - The tooltip text.
      Returns:
      The delegate itself.
      Throws:
      NullPointerException - If the text is null, use an empty string to model the absence of a tooltip.
    • getTooltip

      public final String getTooltip()
      As a delegate to the underlying component, you can use this method to conveniently get the tooltip of the component.

      See JComponent.getToolTipText() for more information.

      Returns:
      The tooltip text.
    • setEnabled

      public final swingtree.AbstractDelegate<C> setEnabled(boolean enabled)
      As a delegate to the underlying component, you can use this method to conveniently enable or disable the component. This method returns the delegate itself, so you can chain calls to this method.

      See JComponent.setEnabled(boolean) for more information.

      Parameters:
      enabled - True if the component should be enabled, false otherwise.
      Returns:
      The delegate itself.
    • isEnabled

      public final boolean isEnabled()
      As a delegate to the underlying component, you can use this method to conveniently check if the component is enabled.

      See Component.isEnabled() for more information.

      Returns:
      True if the component is enabled, false otherwise.
    • setVisible

      public final swingtree.AbstractDelegate<C> setVisible(boolean visible)
      As a delegate to the underlying component, you can use this method to conveniently enable or disable the component. This method returns the delegate itself, so you can chain calls to this method.

      See JComponent.setVisible(boolean) for more information.

      Parameters:
      visible - True if the component should be visible, false otherwise.
      Returns:
      The delegate itself.
    • isVisible

      public final boolean isVisible()
      As a delegate to the underlying component, you can use this method to conveniently check if the component is visible.

      See Component.isVisible() for more information.

      Returns:
      True if the component is visible, false otherwise.
    • setOpaque

      public final swingtree.AbstractDelegate<C> setOpaque(boolean opaque)
      As a delegate to the underlying component, you can use this method to conveniently make the component opaque or transparent. This method returns the delegate itself, so you can chain calls to this method.

      See JComponent.setOpaque(boolean) for more information.

      Parameters:
      opaque - True if the component should be opaque, false otherwise.
      Returns:
      The delegate itself.
    • isOpaque

      public final boolean isOpaque()
      As a delegate to the underlying component, you can use this method to conveniently check if the component is opaque.

      See JComponent.isOpaque() for more information.

      Returns:
      True if the component is opaque, false otherwise.
    • find

      public final <T extends JComponent> OptionalUI<T> find(Class<T> type, String id)
      Use this to query the UI tree and find any JComponent of a particular type and id (the name of the component).
      Type Parameters:
      T - The type parameter of the component which should be found.
      Parameters:
      type - The JComponent type which should be found in the swing tree.
      id - The ide of the JComponent which should be found in the swing tree.
      Returns:
      An Optional instance which may or may not contain the requested component.
    • find

      public final <T extends JComponent> OptionalUI<T> find(Class<T> type, Enum<?> id)
      Use this to query the UI tree and find any JComponent of a particular type and id (the name of the component).
      Type Parameters:
      T - The type parameter of the component which should be found.
      Parameters:
      type - The JComponent type which should be found in the swing tree.
      id - The ide of the JComponent which should be found in the swing tree.
      Returns:
      An Optional instance which may or may not contain the requested component.
    • find

      public final <T extends JComponent> OptionalUI<T> find(Class<T> type, Predicate<T> predicate)
      Use this to query the UI tree and find any JComponent based on a specific type and a predicate which is used to test if a particular component in the tree is the one you are looking for.
      Type Parameters:
      T - The type parameter of the component which should be found.
      Parameters:
      type - The JComponent type which should be found in the swing tree.
      predicate - The predicate which should be used to test the JComponent.
      Returns:
      An Optional instance which may or may not contain the requested component.
    • findAll

      public final <T extends JComponent> List<T> findAll(Class<T> type, Predicate<T> predicate)
      Use this to query the UI tree and find all JComponents based on a specific type and a predicate which is used to test if a particular component in the tree is the one you are looking for.
      Type Parameters:
      T - The type parameter of the component which should be found.
      Parameters:
      type - The JComponent type which should be found in the swing tree.
      predicate - The predicate which should be used to test the JComponent.
      Returns:
      A list of JComponent instances which match the given type and predicate.
    • findAllByGroup

      public final <T extends JComponent> List<T> findAllByGroup(Class<T> type, String group)
      Use this to query the UI tree and find all JComponents of a particular type and also that belong to a particular style group.
      Type Parameters:
      T - The type parameter of the component which should be found.
      Parameters:
      type - The JComponent type which should be found in the swing tree.
      group - The style group which should be used to test the JComponent.
      Returns:
      A list of JComponent instances which match the given type and group.
    • findAllByGroup

      public final List<JComponent> findAllByGroup(String group)
      Use this to query the UI tree and find all JComponents that belong to a particular style group.
      Parameters:
      group - The style group which should be used to check if a particular JComponent belongs to it.
      Returns:
      A list of JComponent instances which all have the given style group.
      Throws:
      NullPointerException - If the group is null.
    • findAllByGroup

      public final <T extends JComponent> List<T> findAllByGroup(Class<T> type, Enum<?> group)
      Use this to query the UI tree and find all JComponents of a particular type and also that belong to a particular style group.
      Type Parameters:
      T - The type parameter of the component which should be found.
      Parameters:
      type - The JComponent type which should be found in the swing tree.
      group - The style group which should be used to test the JComponent.
      Returns:
      A list of JComponent instances which match the given type and predicate.
    • findAllByGroup

      public final List<JComponent> findAllByGroup(Enum<?> group)
      Use this to query the UI tree and find all JComponents that belong to a particular style group.
      Parameters:
      group - The style group which should be used to check if a particular JComponent belongs to it.
      Returns:
      A list of JComponent instances which all have the given style group.
    • paint

      public final void paint(AnimationState state, Painter painter)
      A common use case is to render something on top of the component using the Graphics2D instance of the component. This method allows you to attach a paint task to the component, which the EDT will process in the next repaint event cycle, and remove when the animation expires. This ensures that custom rendering is not erased by a potential repaint of the component after a user event.

      Here is an example of how to use this method as part of a fancy button animation:

      
            UI.button("Click me").withPrefSize(400, 400)
            .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, state -> {
                double r = 300 * state.progress() * it.scale();
                double x = it.mouseX() - r / 2;
                double y = it.mouseY() - r / 2;
                it.paint(state, g -> {
                    g.setColor(new Color(1f, 1f, 0f, (float) (1 - state.progress())));
                    g.fillOval((int) x, (int) y, (int) r, (int) r);
                });
            }))
        
      You may also be interested in doing style animations, if so, maybe consider taking a look at UIForAnySwing.withTransitoryStyle(Event, LifeTime, AnimatedStyler) to see how to do event based styling animations and UIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler) to see how to do 2 state switch based styling animations.
      Parameters:
      state - The current animation state, which is important so that the rendering can be synchronized with the animation.
      painter - The rendering task which should be executed on the EDT at the end of the current event cycle.
    • paint

      public final void paint(UI.ComponentArea area, AnimationState state, Painter painter)
      A common use case is to render something on top of the component using the Graphics2D instance of the component. This method allows you to attach a paint task to the component, which the EDT will process in the next repaint event cycle, and remove when the animation expires. This ensures that custom rendering is not erased by a potential repaint of the component after a user event.
      Additionally, you can specify the area of the component which should be painted.

      Here is an example of how to use this method as part of a button animation:

      
            UI.button("Click me").withPrefSize(400, 400)
            .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, state -> {
                double r = 300 * state.progress() * it.scale();
                double x = it.mouseX() - r / 2;
                double y = it.mouseY() - r / 2;
                it.paint(UI.ComponentArea.BORDER, state, g -> {
                    g.setColor(new Color(1f, 1f, 0f, (float) (1 - state.progress())));
                    g.fillOval((int) x, (int) y, (int) r, (int) r);
                });
            }))
        
      You may also be interested in doing style animations, if so, maybe consider taking a look at UIForAnySwing.withTransitoryStyle(Event, LifeTime, AnimatedStyler) to see how to do event based styling animations and UIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler) to see how to do 2 state switch based styling animations.
      Parameters:
      area - The area of the component which should be painted.
      state - The current animation state, which is important so that the rendering can be synchronized with the animation.
      painter - The rendering task which should be executed on the EDT at the end of the current event cycle.
    • animateStyleFor

      public final void animateStyleFor(double duration, TimeUnit unit, AnimatedStyler<C> styler)
      A common use case is to animate the style of a component when a user event occurs. This method allows you to dispatch a styling animation to the EDT which will cause the component style to updated repeatedly until the animation expires. Because animation styles are applied last, it is guaranteed not to be overwritten by other Styler lambdas. Note that the provided styling will be removed automatically when the animation expires, so no manual cleanup is required.

      Here is an example of how to use this method as part of a fancy styling animation:

      
          UI.button("Click me").withPrefSize(400, 400)
          .onMouseClick( it -> it.animateStyleFor(2, TimeUnit.SECONDS, (state, style) ->
              .borderWidthAt(UI.Edge.BOTTOM, (int)(6 * state.progress()) )
              .borderColor( new Color(0f, 1f, 1f, (float) (1 - state.progress())) )
              .borderRadius( (int)(60 * state.progress()) )
          ))
        
      Not that the effect of this method can also be modelled using animateFor(LifeTime, Animation) and style(AnimationState, Styler) as follows:
      
          UI.button("Click me").withPrefSize(400, 400)
          .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, state -> {
              it.style(state, style -> style
                  // This is the same as the animateStyleFor() method above!
              );
          }))
        
      Also see animateStyleFor(LifeTime, AnimatedStyler) for a version of this method which uses a LifeTime instead of a duration. If you are interested in doing more advanced style animations, consider taking a look at UIForAnySwing.withTransitoryStyle(Event, LifeTime, AnimatedStyler) to see how to do event based styling animations and UIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler) to see how to do 2 state switch based styling animations.
      Parameters:
      duration - The duration of the animation.
      unit - The time unit of the duration.
      styler - The styling animation task which should be executed on the EDT at the end of the current event cycle. It receives both the current animation state and the ComponentStyleDelegate for which you can define the style properties.
    • animateStyleFor

      public final void animateStyleFor(LifeTime lifetime, AnimatedStyler<C> styler)
      A common use case is to animate the style of a component when a user event occurs. This method allows you to dispatch a styling animation to the EDT which will cause the component style to updated repeatedly until the animation expires. Because animation styles are applied last, it is guaranteed not to be overwritten by other Styler lambdas. Note that the provided styling will be removed automatically when the animation expires, so no manual cleanup is required.

      Here is an example of how to use this method as part of a fancy styling animation:

      
          UI.button("Click me").withPrefSize(400, 400)
          .onMouseClick( it -> it.animateStyleFor(UI.lifetime(2, TimeUnit.SECONDS), (state, style) ->
              .borderWidthAt(UI.Edge.BOTTOM, (int)(6 * state.progress()) )
              .borderColor( new Color(0f, 1f, 1f, (float) (1 - state.progress())) )
              .borderRadius( (int)(60 * state.progress()) )
          ))
        
      Not that the effect of this method can also be modelled using animateFor(LifeTime, Animation) and style(AnimationState, Styler) as follows:
      
          UI.button("Click me").withPrefSize(400, 400)
          .onMouseClick( it -> it.animateFor(UI.lifetime(2, TimeUnit.SECONDS), state -> {
              it.style(state, style -> style
                  // This is the same as the animateStyleFor() method above!
              );
          }))
        
      Also see animateStyleFor(double, TimeUnit, AnimatedStyler) for a version of this method which uses a LifeTime instead of a duration. If you are interested in doing more advanced style animations, consider taking a look at UIForAnySwing.withTransitoryStyle(Event, LifeTime, AnimatedStyler) to see how to do event based styling animations and UIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler) to see how to do 2 state switch based styling animations.
      Parameters:
      lifetime - The lifetime of the animation. The animation will be removed automatically when the lifetime expires.
      styler - The styling animation task which should be executed on the EDT at the end of the current event cycle. It receives both the current animation state and the ComponentStyleDelegate for which you can define the style properties.
    • style

      public final void style(AnimationState state, Styler<C> styler)
      A common use case is to style the component based on the current animation state. This method allows you to dispatch a styling task to the EDT which will be executed before the next component repaint. Because animation styles are applied last, it is guaranteed not to be overwritten by other styles. The provided styling will be removed when the animation expires.

      Here is an example of how to use this method as part of a fancy styling animation:

      
            UI.button("Click me").withPrefSize(400, 400)
            .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, state -> {
                it.style(state, style -> style
                    .borderWidth((int)(10 * state.progress()))
                    .borderColor(new Color(1f, 1f, 0f, (float) (1 - state.progress())))
                    .borderRadius((int)(100 * state.progress()))
                );
            }))
        
      Parameters:
      state - The current animation state, which is important so that the styling can be synchronized with the animation.
      styler - The styling task which should be executed on the EDT at the end of the current event cycle.
    • animateFor

      public final Animator animateFor(double duration, TimeUnit unit)
      Exposes access the animation builder API, where you can define the conditions under which the animation should be executed and then dispatch the animation to the EDT through the Animator.go(Animation) method.
      Parameters:
      duration - The duration of the animation.
      unit - The time unit of the duration.
      Returns:
      An Animator instance which can be used to define how the animation should be executed.
    • animateFor

      public final Animator animateFor(LifeTime lifeTime)
      Exposes access the animation builder API, where you can define the conditions under which the animation should be executed and then dispatch the animation to the EDT through the Animator.go(Animation) method.
      Parameters:
      lifeTime - The lifetime of the animation.
      Returns:
      An Animator instance which can be used to define how the animation should be executed.
    • animateFor

      public final void animateFor(LifeTime lifeTime, Animation animation)
      Use this to schedule and run the provided animation to be executed on the EDT. A single animation iteration may be executed multiple times for the given duration in order to achieve a smooth transition.
      Here an example of how to use this method on a "Save" button:
      
        UI.button("Save").withPrefSize(400, 400)
        .onMouseClick( it -> it
          .animateFor(
            UI.lifetime(1, TimeUnit.SECONDS)
            .startingIn( 0.5, TimeUnit.SECONDS )
          )
          .go( myAnimation )
        )
        
      Parameters:
      lifeTime - The lifetime of the animation.
      animation - The animation that should be executed.
    • animateFor

      public final void animateFor(double duration, TimeUnit unit, Animation animation)
      Use this to schedule and run the provided animation to be executed on the EDT. A single animation iteration may be executed multiple times for the given duration in order to achieve a smooth transition.
      Parameters:
      duration - The duration of the animation.
      unit - The time unit of the duration.
      animation - The animation that should be executed.
    • getScale

      public float getScale()
      The number returned by this method is used to scale the UI to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI). Use it inside custom Painter implementations (see paint(AnimationState, Painter)) to scale custom Graphics2D painting operations.
      Returns:
      The current UI scale factor, which is used to scale the UI for high resolution displays (high dots-per-inch, or DPI).
    • scale

      public float scale()
      The number returned by this method is used to scale the UI to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI). Use it inside custom Painter implementations (see paint(AnimationState, Painter)) to scale custom Graphics2D painting operations.
      Returns:
      The current UI scale factor, which is used to scale the UI for high resolution displays (high dots-per-inch, or DPI).
    • scale

      public int scale(int value)
      Use this method inside custom Painter implementations (see paint(AnimationState, Painter)) to scale an int value by the current UI scale factor to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
      Parameters:
      value - The int value to scale.
      Returns:
      The scaled int value.
    • scale

      public float scale(float value)
      Use this method inside custom Painter implementations (see paint(AnimationState, Painter)) to scale a float value by the current UI scale factor to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
      Parameters:
      value - The float value to scale.
      Returns:
      The scaled float value.
    • scale

      public double scale(double value)
      Use this method inside custom Painter implementations (see paint(AnimationState, Painter)) to scale a double value by the current UI scale factor to ensure that the UI is scaled properly for high resolution displays (high dots-per-inch, or DPI).
      Parameters:
      value - The double value to scale.
      Returns:
      The scaled double value.