Class ComponentDelegate<C extends JComponent,E>
- Type Parameters:
C
- The delegate (in most cases origin UI component) type parameter stored by this.E
- The event type parameter of the event stored by this.
- Direct Known Subclasses:
ComponentMouseEventDelegate
Action
),
with the purpose of providing useful context information to the action handler.
You would typically use this to access and change the state of the component, schedule animations for the component or query the tree of neighboring components.
Here a nice usage example where the delegate is used to animate a button:
button("I turn green when you hover over me")
.onMouseEnter( it ->
it.animateFor(0.5, TimeUnit.SECONDS, state -> {
double highlight = 1 - state.progress() * 0.5;
it.setBackgroundColor(highlight, 1, highlight);
})
)
.onMouseExit( it ->
it.animateFor(0.5, TimeUnit.SECONDS, state -> {
double highlight = 0.5 + state.progress() * 0.5;
it.setBackgroundColor(highlight, 1, highlight);
})
)
In this example the it
parameter is a ComponentDelegate<JButton,MouseEvent>
which can be used to access/modify the button, the event, the sibling components...
...but also exposes a nice API to schedule animations for the button.
For some more examples please take a look at the living swing-tree documentation where you can browse a large collection of examples demonstrating how to use the API of this class.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected C
protected final boolean
_isUndefinedColor
(Color color) protected final boolean
_isUndefinedFont
(Font font) 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 theAnimator.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 theAnimator.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
animateStyleFor
(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 tree and find anyJComponent
of a particular type and id (the name of the component).final <T extends JComponent>
OptionalUI<T>Use this to query the UI tree and find anyJComponent
of a particular type and id (the name of the component).final <T extends JComponent>
OptionalUI<T>Use this to query the UI tree and find anyJComponent
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>Use this to query the UI tree and find allJComponent
s 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 allJComponent
s 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 allJComponent
s 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 tree and find allJComponent
s that belong to a particular style group.final List<JComponent>
findAllByGroup
(String group) Use this to query the UI tree and find allJComponent
s that belong to a particular style group.final void
forComponent
(Consumer<C> action) Use this to access the component of this delegate in the swing thread.final void
forSiblinghood
(Consumer<List<JComponent>> action) Use this to access the sibling components of this delegate in the swing thread.final <T extends JComponent>
voidforSiblinghoodOfType
(Class<T> type, Consumer<List<T>> action) Use this to access all sibling components (including the one represented by this delegate) of the specified type in the swing thread.final void
forSiblings
(Consumer<List<JComponent>> action) Use this to access the sibling components of this delegate in the swing thread.final <T extends JComponent>
voidforSiblingsOfType
(Class<T> type, Consumer<List<T>> action) Use this to access the sibling components of this delegate of the specified type in the swing thread.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 C
Exposes the underlying component from which this delegate and user event actions originate.final Cursor
As a delegate to the underlying component, you can use this method to conveniently get theCursor
of the component.final E
getEvent()
final Font
getFont()
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 aPoint
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
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).final List<JComponent>
This method provides a convenient way to access all the children of the parent component of the component this delegate is for.final <T extends JComponent>
List<T>getSiblinghoodOfType
(Class<T> type) Allows you to query the sibling components of the delegated component of the specified type.final List<JComponent>
Exposes the "siblings", which consist of all the child components of the parent of the delegated component except the for the delegated component itself.final <T extends JComponent>
List<T>getSiblingsOfType
(Class<T> type) Allows you to query the sibling components of the delegated component of the specified type.final Size
getSize()
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
getWidth()
As a delegate to the underlying component, you can use this method to conveniently get the width of the component.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.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.final boolean
As a delegate to the underlying component, you can use this method to conveniently check if the component is enabled.final boolean
isOpaque()
As a delegate to the underlying component, you can use this method to conveniently check if the component is opaque.final boolean
As a delegate to the underlying component, you can use this method to conveniently check if the component is visible.final void
paint
(AnimationState state, Painter painter) A common use case is to render something on top of the component using theGraphics2D
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 theGraphics2D
instance of the component.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).double
scale
(double value) Use this method inside customPainter
implementations (seepaint(AnimationState, Painter)
) to scale adouble
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 customPainter
implementations (seepaint(AnimationState, Painter)
) to scale afloat
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 customPainter
implementations (seepaint(AnimationState, Painter)
) to scale anint
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>
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 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>
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>
Delegates to theComponent.setBounds(int, int, int, int)
method of the underlying component.final swingtree.AbstractDelegate<C>
As a delegate to the underlying component, you can use this method to conveniently set theCursor
of the component.final swingtree.AbstractDelegate<C>
As a delegate to the underlying component, you can use this method to conveniently set theUI.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>
As a delegate to the underlying component, you can use this method to conveniently set the font of the component.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.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>
setMaxSize
(Dimension size) 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>
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 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>
setMinSize
(Dimension size) 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>
setMinSize
(Size size) 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>
setPrefSize
(Dimension size) 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>
setPrefSize
(Size size) 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>
As a delegate to the underlying component, you can use this method to conveniently set the size of the component.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.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.
-
Constructor Details
-
ComponentDelegate
-
-
Method Details
-
getComponent
Exposes the underlying component from which this delegate and user event actions originate. This method may only be called by the Swing thread. If another thread calls this method, an exception will be thrown.- Returns:
- The component for which the current
Action
originated. - Throws:
IllegalStateException
- If this method is called from a non-Swing thread.
-
forComponent
Use this to access the component of this delegate in the swing thread. This method will make sure that the passed lambda will be executed by the Swing thread.- Parameters:
action
- The action consuming the component, which will be executed by the Swing thread.
-
getEvent
-
getSiblings
Exposes the "siblings", which consist of all the child components of the parent of the delegated component except the for the delegated component itself.- Returns:
- A list of all siblings excluding the component from which this instance originated.
-
forSiblings
Use this to access the sibling components of this delegate in the swing thread. This method will make sure that the passed lambda will be executed by the Swing thread.- Parameters:
action
- The action consuming a list of all siblings (excluding the component from which this instance originated), which will be executed by the Swing thread.
-
getSiblingsOfType
Allows you to query the sibling components of the delegated component of the specified type. So a list of all siblings which are of the specified type will be returned, excluding the currently delegated component itself.
Note that this method may only be called by the Swing thread. If another thread calls this method, an exception will be thrown. UseforSiblingsOfType(Class, Consumer)
to access the sibling components of the specified type in a thread-safe way.- Type Parameters:
T
- The type of the sibling components to return.- Parameters:
type
- The type class of the sibling components to return.- Returns:
- A list of all siblings of the specified type, excluding the component from which this instance originated.
-
forSiblingsOfType
Use this to access the sibling components of this delegate of the specified type in the swing thread. This method will make sure that the passed lambda will be executed by the Swing thread.- Type Parameters:
T
- TheJComponent
type of the sibling components to return.- Parameters:
type
- The type class of the sibling components to return.action
- The action consuming a list of all siblings of the specified type, excluding the component from which this instance originated, which will be executed by the Swing thread.
-
getSiblinghood
This method provides a convenient way to access all the children of the parent component of the component this delegate is for. Note that this method may only be called by the Swing thread. If another thread calls this method, an exception will be thrown. UseforSiblinghood(Consumer)
to access the sibling components- Returns:
- A list of all siblings including the component from which this instance originated.
-
forSiblinghood
Use this to access the sibling components of this delegate in the swing thread. This method will make sure that the passed lambda will be executed by the Swing thread.- Parameters:
action
- The action consuming a list of all siblings (including the component from which this instance originated), which will be executed by the Swing thread.
-
getSiblinghoodOfType
Allows you to query the sibling components of the delegated component of the specified type. So a list of all siblings which are of the specified type will be returned, possibly including the delegated component itself.
Note that this method may only be called by the Swing thread. If another thread calls this method, an exception will be thrown. UseforSiblinghoodOfType(Class, Consumer)
to access the sibling components of the specified type in a thread-safe way.- Type Parameters:
T
- TheJComponent
type of the sibling components to return.- Parameters:
type
- The type of the sibling components to return.- Returns:
- A list of all siblings of the specified type, including the component from which this instance originated.
-
forSiblinghoodOfType
public final <T extends JComponent> void forSiblinghoodOfType(Class<T> type, Consumer<List<T>> action) Use this to access all sibling components (including the one represented by this delegate) of the specified type in the swing thread. This method will make sure that the passed lambda will be executed by the Swing thread.- Type Parameters:
T
- TheJComponent
type of the sibling components to return.- Parameters:
type
- The type of the sibling components to return.action
- The action consuming a list of all siblings of the specified type, including the component from which this instance originated, which will be executed by the Swing thread.
-
_isUndefinedFont
-
_isUndefinedColor
-
_component
-
_siblingsSource
-
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
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 aPoint
object. The value returned by this method is equal to the value returned bygetX()
andgetY()
.- Returns:
- The location of the component relative to its parent.
-
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 toComponent.getParent()
.- Returns:
- The parent
Container
of 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 isnull
then 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
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
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.UNDEFINED
if 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 isnull
then 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.UNDEFINED
if 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
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
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.UNDEFINED
then 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 isnull
then 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
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
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.- 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
As a delegate to the underlying component, you can use this method to conveniently set theUI.Cursor
of the component.- Parameters:
cursor
- TheUI.Cursor
which should be set.- Returns:
- The delegate itself.
-
setCursor
As a delegate to the underlying component, you can use this method to conveniently set theCursor
of the component.- Parameters:
cursor
- TheCursor
which should be set.- Returns:
- The delegate itself.
-
getCursor
As a delegate to the underlying component, you can use this method to conveniently get theCursor
of the component.- Returns:
- The
Cursor
of 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
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
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.
-
setOpaque
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
Use this to query the UI tree and find anyJComponent
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
- TheJComponent
type which should be found in the swing tree.id
- The ide of theJComponent
which should be found in the swing tree.- Returns:
- An
Optional
instance which may or may not contain the requested component.
-
find
Use this to query the UI tree and find anyJComponent
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
- TheJComponent
type which should be found in the swing tree.id
- The ide of theJComponent
which should be found in the swing tree.- Returns:
- An
Optional
instance which may or may not contain the requested component.
-
find
Use this to query the UI tree and find anyJComponent
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
- TheJComponent
type which should be found in the swing tree.predicate
- The predicate which should be used to test theJComponent
.- Returns:
- An
Optional
instance which may or may not contain the requested component.
-
findAll
Use this to query the UI tree and find allJComponent
s 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
- TheJComponent
type which should be found in the swing tree.predicate
- The predicate which should be used to test theJComponent
.- Returns:
- A list of
JComponent
instances which match the given type and predicate.
-
findAllByGroup
Use this to query the UI tree and find allJComponent
s 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
- TheJComponent
type which should be found in the swing tree.group
- The style group which should be used to test theJComponent
.- Returns:
- A list of
JComponent
instances which match the given type and group.
-
findAllByGroup
Use this to query the UI tree and find allJComponent
s that belong to a particular style group.- Parameters:
group
- The style group which should be used to check if a particularJComponent
belongs to it.- Returns:
- A list of
JComponent
instances which all have the given style group. - Throws:
NullPointerException
- If the group is null.
-
findAllByGroup
Use this to query the UI tree and find allJComponent
s 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
- TheJComponent
type which should be found in the swing tree.group
- The style group which should be used to test theJComponent
.- Returns:
- A list of
JComponent
instances which match the given type and predicate.
-
findAllByGroup
Use this to query the UI tree and find allJComponent
s that belong to a particular style group.- Parameters:
group
- The style group which should be used to check if a particularJComponent
belongs to it.- Returns:
- A list of
JComponent
instances which all have the given style group.
-
paint
A common use case is to render something on top of the component using theGraphics2D
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:
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, 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); }); }))
UIForAnySwing.withTransitoryStyle(Event, 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:
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
A common use case is to render something on top of the component using theGraphics2D
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:
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, 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); }); }))
UIForAnySwing.withTransitoryStyle(Event, 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.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
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 otherStyler
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:
Not that the effect of this method can also be modelled 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(AnimationState, Styler)
as follows:
Also seeUI.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! ); }))
animateStyleFor(LifeTime, AnimatedStyler)
for a version of this method which uses aLifeTime
instead of a duration. If you are interested in doing more advanced style animations, consider taking a look atUIForAnySwing.withTransitoryStyle(Event, 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 theComponentStyleDelegate
for 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 otherStyler
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:
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(AnimationState, Styler)
as follows:
Also seeUI.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! ); }))
animateStyleFor(double, TimeUnit, AnimatedStyler)
for a version of this method which uses aLifeTime
instead of a duration. If you are interested in doing more advanced style animations, consider taking a look atUIForAnySwing.withTransitoryStyle(Event, 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 theComponentStyleDelegate
for 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, 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
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 theAnimator.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
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 theAnimator.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
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.
-
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 customPainter
implementations (seepaint(AnimationState, Painter)
) to scale customGraphics2D
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 customPainter
implementations (seepaint(AnimationState, Painter)
) to scale customGraphics2D
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 customPainter
implementations (seepaint(AnimationState, Painter)
) to scale anint
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
- Theint
value to scale.- Returns:
- The scaled
int
value.
-
scale
public float scale(float value) Use this method inside customPainter
implementations (seepaint(AnimationState, Painter)
) to scale afloat
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
- Thefloat
value to scale.- Returns:
- The scaled
float
value.
-
scale
public double scale(double value) Use this method inside customPainter
implementations (seepaint(AnimationState, Painter)
) to scale adouble
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
- Thedouble
value to scale.- Returns:
- The scaled
double
value.
-