Class AbstractDelegate<C extends JComponent>
- Type Parameters:
C- The type of the component that is delegated.
- Direct Known Subclasses:
ComponentDelegate,SplitButtonDelegate,SplitItemDelegate
Instances of this class are passed to various user event
Action handlers.
You can use this to change the state of the component, schedule animations
for the component or query the tree of the components.-
Method Summary
Modifier and TypeMethodDescriptionprotected final Cprotected final boolean_isUndefinedColor(Color color) Checks if the given color is the undefined color constant with respect to regular object identity instead of value equality.protected final boolean_isUndefinedFont(Font font) Checks if the given font is the undefined font constant with respect to regular object identity instead of value equality.protected final List<JComponent> A library internal utility method that exposes the sibling components of the delegated component.final AnimationDispatcheranimateFor(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 theAnimationDispatcher.go(Animation)method.final voidanimateFor(double duration, TimeUnit unit, Animation animation) Use this to schedule and run the provided animation to be executed on the EDT.final AnimationDispatcheranimateFor(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 theAnimationDispatcher.go(Animation)method.final voidanimateFor(LifeTime lifeTime, Animation animation) Use this to schedule and run the provided animation to be executed on the EDT.final voidanimateStyleFor(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 voidanimateStyleFor(LifeTime lifetime, AnimatedStyler<C> styler) A common use case is to animate the style of a component when a user event occurs.final <T extends JComponent>
OptionalUI<T> Use this to query the UI's component tree and find anyJComponentof a particular type and id (the name of the component).final <T extends JComponent>
OptionalUI<T> Use this to query the UI's component tree and find anyJComponentof a particular type and id (the name of the component).final <T extends JComponent>
OptionalUI<T> Use this to query the UI's component tree and find anyJComponentbased 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> Use this to query the UI's component tree and find allJComponents 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's component tree and find allJComponents 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's component tree and find allJComponents of a particular type and also that belong to a particular style group.final List<JComponent> findAllByGroup(Enum<?> group) Use this to query the UI's component tree and find allJComponents that belong to a particular style group.final List<JComponent> findAllByGroup(String group) Use this to query the UI's component tree and find allJComponents that belong to a particular style group.final Cget()This is a delegate to the underlying component, but not every method of the component is delegated.final ColorAs a delegate to the underlying component, you can use this method to conveniently get the background color of the component.final BorderAs a delegate to the underlying component, you can use this method to conveniently get the border of the component.final BoundsAs a delegate to the underlying component, you can use this method to conveniently get the bounds of the component in the form of an immutableBoundsvalue object.final CursorAs a delegate to the underlying component, you can use this method to conveniently get theCursorof the component.final FontgetFont()As a delegate to the underlying component, you can use this method to conveniently get the font of the component.final ColorAs a delegate to the underlying component, you can use this method to conveniently get the foreground color of the component.final intExposes the height of the component in "developer pixel" pixel.final PositionThis method allows you to access the location of the delegated component r elative to its parent in "developer pixel space" instead of "component pixel space".final SizeExposes the maximum size of the component in DPI agnostic "developer pixels" which are computed by dividing the already scaled maximum width and height of the component in "component pixels" by theUI.scale()factor.
The maximum size of a component is used by the layout manager to determine the size of the component.final SizeExposes the minimum size of the component in DPI agnostic "developer pixels" which are computed by dividing the already scaled minimum component width and height in "component pixels" by theUI.scale()factor.
The minimum size is used by the layout manager to determine the size of the component.final ContainerThis is a component delegate API, which means that it represents the API of a wrapped component.final SizeExposes the preferred size of the component in DPI agnostic "developer pixels" which are computed by dividing the already scaled preferred component width and height in "component pixels" by theUI.scale()factor.
The preferred size is used by the layout manager to determine the size of the component.final SizegetSize()Exposes the size of the delegated component in "developer pixel".final Stringfinal intgetWidth()Exposes the width of the underlying component in "developer pixel".final intgetX()Allows you to access the x-coordinate of the delegated component relative to its parent, and scaled to "developer pixel space" instead of "component pixel space". This means that even if your component and its placement was upscaled for a particular high DPI environment for example, then you will still receive a consistent coordinate.final intgetY()Allows you to access the y-coordinate of the delegated component relative to its parent, and scaled to "developer pixel space" instead of "component pixel space". This means that even if your component and its placement was upscaled for a particular high DPI environment for example, then you will still receive a consistent coordinate.final booleanAs a delegate to the underlying component, you can use this method to conveniently check if the component is enabled.final booleanisOpaque()As a delegate to the underlying component, you can use this method to conveniently check if the component is opaque.final booleanAs a delegate to the underlying component, you can use this method to conveniently check if the component is visible.final voidpaint(AnimationStatus status, Painter painter) A common use case is to render something on top of theUI.ComponentArea.BODYof the component using theGraphics2Dinstance of the component.final voidpaint(UI.ComponentArea area, AnimationStatus status, Painter painter) A common use case is to render something on top of the component using theGraphics2Dinstance of the component.final voidpaint(UI.ComponentArea area, UI.Layer layer, AnimationStatus status, Painter painter) A common use case is to render something on top of the component using theGraphics2Dinstance used by the component to render itself.final voidpaint(UI.Layer layer, AnimationStatus status, Painter painter) A common use case is to render something on top of theUI.ComponentArea.BODYof the component using theGraphics2Dinstance of the component.final voidparentDelegate(sprouts.Action<AbstractDelegate<JComponent>> action) Use this method to delegate to the parent of the component.final 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.final 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 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 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 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 AbstractDelegate<C> As a delegate to the underlying component, you can use this method to conveniently set the border of the component.final AbstractDelegate<C> setBounds(int x, int y, int width, int height) Allows you to specify new bounds for the delegated component in "developer pixel space" and then have them scaled and set as "component pixel size", which may be scaled for hgigh DPI environments by theUI.scale()factor.final AbstractDelegate<C> As a delegate to the underlying component, you can use this method to conveniently set the bounds of the component.final AbstractDelegate<C> Delegates to theComponent.setBounds(int, int, int, int)method of the underlying component.final AbstractDelegate<C> As a delegate to the underlying component, you can use this method to conveniently set theCursorof the component.final AbstractDelegate<C> As a delegate to the underlying component, you can use this method to conveniently set theUI.Cursorof the component.final 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 AbstractDelegate<C> As a delegate to the underlying component, you can use this method to conveniently set the font of the component.final 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.final 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 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 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 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 AbstractDelegate<C> setHeight(int height) You can use this method to set the height of the delegated component in "developer pixel".final AbstractDelegate<C> setMaxHeight(int height) Takes a new maximum height for the component in "developer pixel" and applies it as "component pixels".final 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 in "developer pixel".final AbstractDelegate<C> setMaxSize(Dimension size) Deprecated.final 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.final 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 in "developer pixel".final 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 AbstractDelegate<C> setMinSize(int width, int height) This method allows you to set the minimum size of the delegated component in "developer pixels" instead of "component pixels".final AbstractDelegate<C> setMinSize(Dimension size) Deprecated.final 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 in developer pixel size.final 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 AbstractDelegate<C> setPrefHeight(int height) Allows you to set the preferred height of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale().final AbstractDelegate<C> setPrefSize(int width, int height) Allows you to set the preferred width and height of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale().final AbstractDelegate<C> setPrefSize(Dimension size) Deprecated.UsesetPrefSize(Size)instead of this method.final AbstractDelegate<C> setPrefSize(Size size) Allows you to set the preferred size of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale().final AbstractDelegate<C> setPrefWidth(int width) Allows you to set the preferred width of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale().final AbstractDelegate<C> setSize(int width, int height) Takes two new width and height for the component in "developer pixel" and applies it as "component pixels".final AbstractDelegate<C> Deprecated.UsesetSize(Size)instead of this method!final AbstractDelegate<C> Takes a newSizefor the component in "developer pixel" and applies it as "component pixels".final 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.final 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 AbstractDelegate<C> setWidth(int width) Takes a new width for the underlying component in "developer pixel" and applies it as "component pixels".shapeOf(UI.ComponentArea area) You can use this method to access a specificUI.ComponentAreaof the component, which is useful if you do custom painting.final voidstyle(AnimationStatus state, Styler<C> styler) A common use case is to style the component based on the current animation state.
-
Method Details
-
_isUndefinedFont
Checks if the given font is the undefined font constant with respect to regular object identity instead of value equality. This is a deliberate design choice to allow the user to use theUI.Font.UNDEFINEDconstant instead ofnullas a placeholder for the absence of a font.- Parameters:
font- The font to check.- Returns:
trueif the font is the undefined font constant,falseotherwise.
-
_isUndefinedColor
Checks if the given color is the undefined color constant with respect to regular object identity instead of value equality. This is a deliberate design choice to allow the user to use theUI.Color.UNDEFINEDconstant instead ofnullas a placeholder for the absence of a color.- Parameters:
color- The color to check.- Returns:
trueif the color is the undefined color constant,falseotherwise.
-
_component
-
_siblingsSource
A library internal utility method that exposes the sibling components of the delegated component.- Returns:
- A list of sibling components.
-
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()Allows you to access the x-coordinate of the delegated component relative to its parent, and scaled to "developer pixel space" instead of "component pixel space". This means that even if your component and its placement was upscaled for a particular high DPI environment for example, then you will still receive a consistent coordinate.- Returns:
- The x-coordinate of the component relative to its parent and in "developer pixel space" (without DPI aware scaling applied).
-
getY
public final int getY()Allows you to access the y-coordinate of the delegated component relative to its parent, and scaled to "developer pixel space" instead of "component pixel space". This means that even if your component and its placement was upscaled for a particular high DPI environment for example, then you will still receive a consistent coordinate.- Returns:
- The y-coordinate of the component relative to its parent and in "developer pixel space" (without DPI aware scaling applied).
-
getLocation
This method allows you to access the location of the delegated component r elative to its parent in "developer pixel space" instead of "component pixel space". It returns an immutablePositionobject holding both x and y components which are equal to the values available throughgetX()andgetY().- Returns:
- The location of the component relative to its parent in "developer pixel space" (without DPI scaling applied).
-
getParent
This is a component delegate API, which means that it represents the API of a wrapped component. So this method allows you to access the parent of the underlying component. In essence, this is a delegate toComponent.getParent().- Returns:
- The parent
Containerof the underlying component. - Throws:
IllegalStateException- If the accessing thread is not the event dispatch thread.
-
setBackground
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 isnullthen this component will inherit the background color of its parent.- Returns:
- The delegate itself.
-
setBackgroundColor
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
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
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
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
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.UNDEFINEDif the component does not have a background color (i.e.Component.getBackground()returnsnull). The return value will never benull.
-
setForeground
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 isnullthen this component will inherit the foreground color of its parent.- Returns:
- The delegate itself.
-
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.UNDEFINEDif the component does not have a foreground color (i.e.Component.getForeground()returnsnull). The return value will never benull.
-
setForegroundColor
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
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
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
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
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 isUI.Font.UNDEFINEDthen this component will inherit the font of its parent. Null is not allowed.- Returns:
- The delegate itself.
-
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
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 isnullthen this component will inherit the border of its parent.- Returns:
- The delegate itself.
-
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
Allows you to specify new bounds for the delegated component in "developer pixel space" and then have them scaled and set as "component pixel size", which may be scaled for hgigh DPI environments by theUI.scale()factor. 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
Delegates to theComponent.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. Important: The supplied bounds are interpreted as "being in developer pixel space" without any scaling factor applied to it. And so this method will scale the bounds to DPI aware "component pixel space" by multiplying byUI.scale().- 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
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
Important: The suppliedComponent.setBounds(Rectangle)for more information.Rectangleis interpreted as "being in developer pixel space" without any scaling factor applied to it. And so this method will scale the bounds to DPI aware "component pixel space" by multiplying byUI.scale().- 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
As a delegate to the underlying component, you can use this method to conveniently get the bounds of the component in the form of an immutableBoundsvalue object. The bounds consist of a location and a size which are relative to the component's parent.See
Important: The returnedComponent.getBounds()for more information.Rectangleis scaled to "developer pixel space" and not necessarily in "component pixel space".- Returns:
- The bounds of the component in scaling agnostic "developer pixel space". This is relative to the component's parent.
-
shapeOf
You can use this method to access a specificUI.ComponentAreaof the component, which is useful if you do custom painting. This method returns anOptionalvalue, which means that the component area may not be present. TheUI.ComponentArea.BORDERfor example, may not be present in case of there not being a border width defined throughUIForAnySwing.withStyle(Styler).See
ComponentExtension.getComponentArea(UI.ComponentArea)for more information.- Parameters:
area- The component area to access.- Returns:
- An optional value that contains the component area if it is present.
-
setPrefSize
Deprecated.UsesetPrefSize(Size)instead of this method.Allows you to set the preferred size of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale(). 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
Allows you to set the preferred size of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale(). 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
Also note that the supplied size is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setPreferredSize(Dimension)for more information.
This method will scale the supplied size automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
size- The preferred size of the component in developer pixel size.- Returns:
- The delegate itself.
-
setPrefSize
Allows you to set the preferred width and height of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale(). 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
Also note that the supplied size is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setPreferredSize(Dimension)for more information.
This method will scale the supplied width and height automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
width- The preferred width of the component in developer pixels (not scaled for high DPI).height- The preferred height of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setPrefWidth
Allows you to set the preferred width of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale(). 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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setPrefHeight
Allows you to set the preferred height of the component in DPI agnostic "developer pixels", which are automatically converted to DPI aware "component pixels" usingUI.scale(). 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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
getPrefSize
Exposes the preferred size of the component in DPI agnostic "developer pixels" which are computed by dividing the already scaled preferred component width and height in "component pixels" by theUI.scale()factor.
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 scaled to "developer pixel size".
-
setMinSize
Deprecated.UsesetMinSize(Size)instead!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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setMinSize
As a delegate to the underlying component, you can use this method to conveniently set the minimum size of the component in developer pixel size. 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
Also note that the supplied size is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setMinimumSize(Dimension)for more information about the meaning of this property.
This method will scale the supplied size automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
size- The minimum size of the component in developer pixel size, orSize.unknown()to set the minimum size to being "undefined"/"null".- Returns:
- The delegate itself.
- Throws:
NullPointerException- if the supplied size is null.
-
setMinSize
This method allows you to set the minimum size of the delegated component in "developer pixels" instead of "component pixels". The dimension you supply to this method will be scale to "component pixels" for you, so you don't have to rely on component pixel space in your code (which varies depending on theUI.scale()). 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 in developer pixels (not scaled for high DPI).height- The minimum height of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setMinWidth
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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setMinHeight
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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
getMinSize
Exposes the minimum size of the component in DPI agnostic "developer pixels" which are computed by dividing the already scaled minimum component width and height in "component pixels" by theUI.scale()factor.
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
Deprecated.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
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
Also note that the supplied size is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setMaximumSize(Dimension)for more information.
This method will scale the supplied size automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
size- The maximum size of the component in developer pixel size, orSize.unknown()to set the maximum size to being "undefined"/"null".- Returns:
- The delegate itself.
- Throws:
NullPointerException- if the supplied size isnull.
-
setMaxSize
As a delegate to the underlying component, you can use this method to conveniently set the maximum size of the component in "developer pixel". 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
Also note that the supplied size is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setMaximumSize(Dimension)for more information.
This method will scale the supplied size automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
width- The maximum width of the component in developer pixels (not scaled for high DPI).height- The maximum height of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setMaxWidth
As a delegate to the underlying component, you can use this method to conveniently set the maximum width of the component in "developer pixel". 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
Also note that the supplied width is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setMaximumSize(Dimension)for more information.
This method will scale the supplied width automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
width- The maximum width of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setMaxHeight
Takes a new maximum height for the component in "developer pixel" and applies it as "component pixels". This means that the supplied height will be scaled to dynamic "component pixels" through multiplication with theUI.scale()factor.
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
Also note that the supplied height is treated as being measured in "developer pixel size", which are defined as pixels without the UI scaling factor applied to them.Component.setMaximumSize(Dimension)for more information.
This method will scale the supplied height automatically for you, and therefore you as a developer may define dimensions in your GUI code consistently, without sacrificing dynamic DPI scaling.- Parameters:
height- The maximum height of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
getMaxSize
Exposes the maximum size of the component in DPI agnostic "developer pixels" which are computed by dividing the already scaled maximum width and height of the component in "component pixels" by theUI.scale()factor.
The maximum size of a component 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 in "developer pixels".
-
setSize
Deprecated.UsesetSize(Size)instead of this method!You can use this method to set the size of the component in "developer pixel", meaning that the supplied dimensions will be scaled to dynamic "component pixels" using theUI.scale()factor.
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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setSize
Takes a newSizefor the component in "developer pixel" and applies it as "component pixels". This means that the supplied dimensions will be scaled to dynamic "component pixels" through multiplication with theUI.scale()factor.
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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setSize
Takes two new width and height for the component in "developer pixel" and applies it as "component pixels". This means that the supplied dimensions will be scaled to dynamic "component pixels" through multiplication with theUI.scale()factor.
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 in developer pixels (not scaled for high DPI).height- The height of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setWidth
Takes a new width for the underlying component in "developer pixel" and applies it as "component pixels". This means that the supplied width will be scaled to dynamic "component pixels" through multiplication with theUI.scale()factor.
This method returns the delegate itself, so you can chain calls to this method. The regular size of a component is typically managed and set by the layout manager of a component. So you may not want to set this in most cases...See
Component.setSize(Dimension)for more information.- Parameters:
width- The width of the component in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
setHeight
You can use this method to set the height of the delegated component in "developer pixel". The value you pass to this method will be scaled byUI.scale(int)and then set. 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 in developer pixels (not scaled for high DPI).- Returns:
- The delegate itself.
-
getSize
Exposes the size of the delegated component in "developer pixel". Theis property is typically managed and set by the layout manager.See
Component.getSize()for more information.- Returns:
- The size of the component.
-
getWidth
public final int getWidth()Exposes the width of the underlying component in "developer pixel". Theis property is typically managed and set by the layout manager.See
Component.getSize()for more information.- Returns:
- The width of the component in developer pixels (not scaled for high DPI).
-
getHeight
public final int getHeight()Exposes the height of the component in "developer pixel" pixel. Theis property is typically managed and set by the layout manager.See
Component.getSize()for more information.- Returns:
- The height of the component in developer pixels (not scaled for high DPI).
-
setCursor
As a delegate to the underlying component, you can use this method to conveniently set theUI.Cursorof the component.- Parameters:
cursor- TheUI.Cursorwhich should be set.- Returns:
- The delegate itself.
- Throws:
NullPointerException- if the supplied enum instance isnull!
-
setCursor
As a delegate to the underlying component, you can use this method to conveniently set theCursorof the component.- Parameters:
cursor- TheCursorwhich should be set.- Returns:
- The delegate itself.
-
getCursor
As a delegate to the underlying component, you can use this method to conveniently get theCursorof the component.- Returns:
- The
Cursorof the component.
-
setTooltip
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
Exposes the tooltipStringof the component or an emptyStringif the component does not have a tooltip. Note that this method will never returnnull.See
JComponent.getToolTipText()for more information.- Returns:
- The tooltip text or an empty
Stringif this component does not have a tooltip, butnullis never returned!
-
setEnabled
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
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.
-
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
Use this to query the UI's component tree and find anyJComponentof 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- TheJComponenttype which should be found in the swing tree.id- The ide of theJComponentwhich should be found in the swing tree.- Returns:
- An
Optionalinstance which may or may not contain the requested component.
-
find
Use this to query the UI's component tree and find anyJComponentof 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- TheJComponenttype which should be found in the swing tree.id- The ide of theJComponentwhich should be found in the swing tree.- Returns:
- An
Optionalinstance which may or may not contain the requested component.
-
find
Use this to query the UI's component tree and find anyJComponentbased 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- TheJComponenttype which should be found in the swing tree.predicate- The predicate which should be used to test theJComponent.- Returns:
- An
Optionalinstance which may or may not contain the requested component.
-
findAll
Use this to query the UI's component tree and find allJComponents 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- TheJComponenttype which should be found in the swing tree.predicate- The predicate which should be used to test theJComponent.- Returns:
- A list of
JComponentinstances which match the given type and predicate.
-
findAllByGroup
Use this to query the UI's component tree and find allJComponents 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- TheJComponenttype which should be found in the swing tree.group- The style group which should be used to test theJComponent.- Returns:
- A list of
JComponentinstances which match the given type and group.
-
findAllByGroup
Use this to query the UI's component tree and find allJComponents that belong to a particular style group.- Parameters:
group- The style group which should be used to check if a particularJComponentbelongs to it.- Returns:
- A list of
JComponentinstances which all have the given style group. - Throws:
NullPointerException- If the group is null.
-
findAllByGroup
Use this to query the UI's component tree and find allJComponents 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- TheJComponenttype which should be found in the swing tree.group- The style group which should be used to test theJComponent.- Returns:
- A list of
JComponentinstances which match the given type and predicate.
-
findAllByGroup
Use this to query the UI's component tree and find allJComponents that belong to a particular style group.- Parameters:
group- The style group which should be used to check if a particularJComponentbelongs to it.- Returns:
- A list of
JComponentinstances which all have the given style group.
-
paint
A common use case is to render something on top of theUI.ComponentArea.BODYof the component using theGraphics2Dinstance 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:
You may also be interested in doing style animations, if so, maybe consider taking a look atUI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, status -> { double r = 300 * status.progress(); double x = it.mouseX() - r / 2; double y = it.mouseY() - r / 2; it.paint(status, g -> { g.setColor(new Color(1f, 1f, 0f, (float) (1 - status.progress()))); g.fillOval((int) x, (int) y, (int) r, (int) r); }); }))UIForAnySwing.withTransitoryStyle(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler)to see how to do 2 state switch based styling animations.- Parameters:
status- The current animation progress status, 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
A common use case is to render something on top of the component using theGraphics2Dinstance 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:
You may also be interested in doing style animations, if so, maybe consider taking a look atUI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, status -> { double r = 300 * status.progress(); 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 - status.progress()))); g.fillOval((int) x, (int) y, (int) r, (int) r); }); }))UIForAnySwing.withTransitoryStyle(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.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.status- The current animation progress status, which needs to be provided 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
A common use case is to render something on top of theUI.ComponentArea.BODYof the component using theGraphics2Dinstance 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:
You may also be interested in doing style animations, if so, maybe consider taking a look atUI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, status -> { double r = 300 * status.progress(); double x = it.mouseX() - r / 2; double y = it.mouseY() - r / 2; it.paint(UI.Layer.CONTENT, status, g -> { g.setColor(new Color(1f, 1f, 0f, (float) (1 - status.progress()))); g.fillOval((int) x, (int) y, (int) r, (int) r); }); }))UIForAnySwing.withTransitoryStyle(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler)to see how to do 2 state switch based styling animations.- Parameters:
layer- The layer of the component which should be painted on.status- The current animation progress status, 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, UI.Layer layer, AnimationStatus status, Painter painter) A common use case is to render something on top of the component using theGraphics2Dinstance used by the component to render itself. 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 as well as a layer onto which the painter should paint.Here is an example of how to use this method as part of a button animation:
You may also be interested in doing style animations, if so, maybe consider taking a look atUI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, status -> { double r = 300 * status.progress(); double x = it.mouseX() - r / 2; double y = it.mouseY() - r / 2; it.paint(UI.ComponentArea.BODY, UI.Layer.CONTENT, state, g -> { g.setColor(new Color(1f, 1f, 0f, (float) (1 - status.progress()))); g.fillOval((int) x, (int) y, (int) r, (int) r); }); }))UIForAnySwing.withTransitoryStyle(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.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.layer- The layer of the component which should be painted.status- The current animation progress status, which needs to be provided so that the rendering can be synchronized with the animation.painter- An implementation of a simple functional interface receiving aGraphics2Dinstance for doing paint operations...
-
parentDelegate
Use this method to delegate to the parent of the component. This is useful if you want to apply a style or animation to the parent of a component which just received an event, like a mouse click event.Here is an example demonstrating how to apply a style to the parent of a component when it is clicked:
UI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it .parentDelegate( parent -> parent .style( style -> style .borderWidth(6) .borderColor(Color.RED) .borderRadius(60) ) ) )
And here another more advanced example demonstrating how to do animated painting on the parent of a component that is being dragged away:
The paint method draws a circle around the drag origin of the drag event which gets smaller and more opaque as the animation progresses for a duration of 1 second.label("Drag me away") .withDragAway( conf -> conf .onDragStart( it -> { it.parentDelegate( parent -> parent .animateFor(1, TimeUnit.SECONDS, status -> { double r = 320 * status.fadeOut(); double x = it.getEvent().getDragOrigin().getX() - r / 2; double y = it.getEvent().getDragOrigin().getY() - r / 2; parent.paint(status, g -> { g.setColor(new Color(0f, 1f, 1f, (float) status.fadeIn())); 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(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler)to see how to do 2 state switch based styling animations.- Parameters:
action- The action which should be executed on the delegate of the parent component.
-
animateStyleFor
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 otherStylerlambdas. 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:
You can achieve the same effect usingUI.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()) ) ))animateFor(LifeTime, Animation)andstyle(AnimationStatus, Styler)as follows:
Also seeUI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it.animateFor(2, TimeUnit.SECONDS, status -> { it.style(status, style -> style // This is the same as the animateStyleFor() method above! ); }))animateStyleFor(LifeTime, AnimatedStyler)for a version of this method which uses aLifeTimeinstead of a duration. If you are interested in doing more advanced style animations, consider taking a look atUIForAnySwing.withTransitoryStyle(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.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 theComponentStyleDelegatefor which you can define the style properties.
-
animateStyleFor
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 otherStylerlambdas. 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:
Not that the effect of this method can also be modelled usingUI.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()) ) ))animateFor(LifeTime, Animation)andstyle(AnimationStatus, Styler)as follows:
Also seeUI.button("Click me").withPrefSize(400, 400) .onMouseClick( it -> it.animateFor(UI.lifetime(2, TimeUnit.SECONDS), status -> { it.style(status, style -> style // This is the same as the animateStyleFor() method above! ); }))animateStyleFor(double, TimeUnit, AnimatedStyler)for a version of this method which uses aLifeTimeinstead of a duration. If you are interested in doing more advanced style animations, consider taking a look atUIForAnySwing.withTransitoryStyle(sprouts.Observable, LifeTime, AnimatedStyler)to see how to do event based styling animations andUIForAnySwing.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 theComponentStyleDelegatefor which you can define the style properties.
-
style
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, status -> { it.style(status, style -> style .borderWidth((int)(10 * status.progress())) .borderColor(new Color(1f, 1f, 0f, (float) (1 - status.progress()))) .borderRadius((int)(100 * status.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
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 theAnimationDispatcher.go(Animation)method.- Parameters:
duration- The duration of the animation.unit- The time unit of the duration.- Returns:
- An
AnimationDispatcherinstance which can be used to define how the animation should be executed.
-
animateFor
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 theAnimationDispatcher.go(Animation)method.- Parameters:
lifeTime- The lifetime of the animation.- Returns:
- An
AnimationDispatcherinstance which can be used to define how the animation should be executed.
-
animateFor
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
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.
-
setMinSize(Size)instead!