Class UIForAnySwing<I,C extends JComponent>
- Type Parameters:
I
- The concrete extension of theUIForAnything
.C
- The type parameter for the component type wrapped by an instance of this class.
- Direct Known Subclasses:
UIForAnyButton
,UIForAnyScrollPane
,UIForAnyTextComponent
,UIForBox
,UIForCombo
,UIForIcon
,UIForLabel
,UIForList
,UIForPanel
,UIForPopup
,UIForProgressBar
,UIForSeparator
,UIForSlider
,UIForSpinner
,UIForSplitPane
,UIForSwing
,UIForTabbedPane
,UIForTable
,UIForTableHeader
,UIForToolBar
JComponent
instance.
This is the most generic builder type and therefore abstract super-type for almost all other builders.
This builder defines nested building for anything extending the JComponent
class.
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
_addComponentTo
(C thisComponent, JComponent addedComponent, @Nullable AddConstraint constraints) This builder class expects its implementations to be builder types for anything which can be built in a nested tree-like structure.protected <M> void
_addViewableProps
(sprouts.Val<sprouts.Tuple<M>> models, @Nullable AddConstraint attr, swingtree.ModelToViewConverter<M> viewSupplier, C thisComponent) protected <M> void
_addViewableProps
(sprouts.Vals<M> models, @Nullable AddConstraint attr, swingtree.ModelToViewConverter<M> viewSupplier, C thisComponent) protected final boolean
_isUndefinedColor
(Color color) protected final boolean
_isUndefinedFont
(Font font) protected void
_setBackground
(JComponent thisComponent, Color color) protected void
_setEnabled
(C c, boolean isEnabled) protected final void
_setMinHeight
(C component, int height) protected final void
_setMinWidth
(C component, int width) protected final void
_setPrefWidth
(C component, int width) final <B extends UIForAnySwing<?,
?>>
IUse this to nest builder types into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance.final <E extends JComponent>
IUse this to nestJComponent
types into this builder to effectively plug the providedJComponent
s into theJComponent
type wrapped by this builder instance.final <M> I
add
(String attr, sprouts.Val<M> model, ViewSupplier<M> viewSupplier) This allows you to dynamically generate a view for the item of a property (usually a property holding a sub-view model) and automatically regenerate the view when the property changes.final <T extends JComponent>
Iadd
(String attr, UIForAnySwing<?, T> builder) Use this to nest builder nodes into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance.final <B extends UIForAnySwing<?,
?>>
Iadd
(net.miginfocom.layout.CC attr, B... builders) Use this to nest builder types into this builder to effectively plug theJComponent
s wrapped by the provided builders into theJComponent
type wrapped by this builder instance.final <M> I
add
(sprouts.Val<M> model, ViewSupplier<M> viewSupplier) This allows you to dynamically generate a view for the item of a property (usually a property holding a sub-view model) and automatically regenerate the view when the property changes.final <B extends UIForAnySwing<?,
?>>
Iadd
(AddConstraint attr, B... builders) Use this to nest builder types into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance.final <E extends JComponent>
Iadd
(AddConstraint attr, E... components) Use this to nestJComponent
types into this builder to effectively plug the providedJComponent
s into theJComponent
type wrapped by this builder instance.final <M> I
add
(AddConstraint attr, sprouts.Val<M> model, ViewSupplier<M> viewSupplier) This allows you to dynamically generate a view for the item of a property (usually a property holding a sub-view model) and automatically regenerate the view when the property changes.final <T extends JComponent>
Iadd
(AddConstraint attr, UIForAnySwing<?, T> builder) Use this to nest builder nodes into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance.final <M> I
addAll
(String attr, sprouts.Val<sprouts.Tuple<M>> models, ViewSupplier<M> viewSupplier) final <M> I
addAll
(String attr, sprouts.Vals<M> models, ViewSupplier<M> viewSupplier) This allows you to dynamically generate views for the items in aVals
property list and automatically regenerate the view when any of the items change.final <M> I
addAll
(sprouts.Val<sprouts.Tuple<M>> models, ViewSupplier<M> viewSupplier) Dynamically generate views for the items in aTuple
of items, and automatically regenerate the view when any of the items in the tuple change.final <M> I
addAll
(sprouts.Vals<M> models, ViewSupplier<M> viewSupplier) This allows you to dynamically generate views for the items in aVals
property list and automatically regenerate the view when any of the items change.final <M> I
addAll
(AddConstraint attr, sprouts.Val<sprouts.Tuple<M>> viewables, ViewSupplier<M> viewSupplier) final <M> I
addAll
(AddConstraint attr, sprouts.Vals<M> models, ViewSupplier<M> viewSupplier) This allows you to dynamically generate views for the items in aVals
property list and automatically regenerate the view when any of the items change.final I
doUpdates
(int delay, sprouts.Action<ComponentDelegate<C, ActionEvent>> onUpdate) Use this to register periodic update actions which should be called based on the provideddelay
!
The following example produces a label which will display the current date.group
(E... groupTags) This method is part of the SwingTree style API, and it allows you to add this component to an enum based style group.final I
This method is part of the SwingTree style API, and it allows you to add this component to a style group.id
(E id) This method exposes a concise way to set an enum based identifier for the component represented by this builder chain.final I
This method exposes a concise way to set an identifier for the component represented by this builder chain.final I
isEnabledIf
(boolean isEnabled) Use this to enable or disable the wrapped UI component.isEnabledIf
(E enumValue, sprouts.Val<E> enumProperty) Use this to make the wrapped UI component dynamically enabled or disabled, based on the equality between the supplied enum value and enum property.final I
isEnabledIf
(sprouts.Val<Boolean> isEnabled) Use this to dynamically enable or disable the wrapped UI component.final I
isEnabledIfNot
(boolean isEnabled) This is the inverse ofisEnabledIf(boolean)
.isEnabledIfNot
(E enumValue, sprouts.Val<E> enumProperty) This is the inverse ofisEnabledIf(Enum, Val)
.final I
isEnabledIfNot
(sprouts.Val<Boolean> isEnabled) This is the inverse ofisEnabledIf(Val)
.final I
isFocusableIf
(boolean isFocusable) Use this to make the wrapped UI component focusable.isFocusableIf
(E enumValue, sprouts.Val<E> enumProperty) Use this to make the wrapped UI component dynamically focusable or non-focusable based on the equality between the supplied enum value and enum property.final I
isFocusableIf
(sprouts.Val<Boolean> isFocusable) Use this to dynamically make the wrapped UI component focusable.final I
isFocusableIfNot
(boolean notFocusable) Use this to make the wrapped UI component focusable if a certain condition is not met.isFocusableIfNot
(E enumValue, sprouts.Val<E> enumProperty) This is the inverse ofisFocusableIf(Enum, Val)
.final I
isFocusableIfNot
(sprouts.Val<Boolean> isFocusable) Use this to dynamically make the wrapped UI component focusable.final I
isValidIf
(UIVerifier<C> verifier) This allows you to register validation logic for the wrapped UI component.final I
isVisibleIf
(boolean isVisible) Make the underlyingJComponent
type visible or invisible depending on the supplied boolean value.isVisibleIf
(E enumValue, sprouts.Val<E> enumProperty) Make the underlyingJComponent
type dynamically visible or invisible based on the equality between the supplied enum value and enum property.final I
isVisibleIf
(sprouts.Val<Boolean> isVisible) Make the underlyingJComponent
type dynamically visible or invisible through the suppliedVal
property, which is automatically bound to theJComponent.setVisible(boolean)
method of the underlyingJComponent
type.final I
isVisibleIfNot
(boolean isVisible) This is the inverse ofisVisibleIf(boolean)
, and it is used to make the underlyingJComponent
type visible or invisible.isVisibleIfNot
(E enumValue, sprouts.Val<E> enumProperty) This is the inverse ofisVisibleIf(Enum, Val)
, and it is used to make the underlyingJComponent
type dynamically visible or invisible.final I
isVisibleIfNot
(sprouts.Val<Boolean> isVisible) This is the inverse ofisVisibleIf(Val)
, and it is used to make the underlyingJComponent
type dynamically visible or invisible.final I
Use this to make the wrapped UI component grab the input focus.final I
Deprecated.final I
Deprecated.SwingTree considers the opaqueness a property which emerges from the style configuration of the component.final <E extends sprouts.Observable>
Ion
(E observableEvent, sprouts.Action<ComponentDelegate<C, E>> action) Use this to attach a componentAction
event handler to a functionally suppliedObservable
event in order to implement a custom user event system.final <E extends sprouts.Observable>
Ion
(Function<C, E> eventSource, sprouts.Action<ComponentDelegate<C, E>> action) This is a logical extension of theon(Observable, Action)
method.final I
onCharTyped
(sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyTyped) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the provided character.final I
onFocusGain
(sprouts.Action<ComponentDelegate<C, ComponentEvent>> onFocus) Adds the suppliedAction
wrapped in aFocusListener
to the component, to receive those focus events where the wrapped component gains input focus.final I
onFocusLoss
(sprouts.Action<ComponentDelegate<C, ComponentEvent>> onFocus) Adds the suppliedAction
wrapped in a focus listener to receive those focus events where the wrapped component loses input focus.final I
onHidden
(sprouts.Action<ComponentDelegate<C, AncestorEvent>> onHidden) Adds the suppliedAction
wrapped in aAncestorListener
to the component, to receive calls when the wrapped component becomes invisible on the users screen.final I
onKeyPress
(sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyPressed) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives keyboard input.final I
onKeyRelease
(sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyReleased) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives keyboard input.final I
onKeyTyped
(sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyTyped) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives keyboard input.final I
onMouseClick
(sprouts.Action<ComponentMouseEventDelegate<C>> onClick) Calls the provided action event handler when the mouse gets pressed and then released.final I
onMouseDrag
(sprouts.Action<ComponentDragEventDelegate<C>> onDrag) Use this to register and catch genericMouseListener
based mouse drag events on this UI component.final I
onMouseEnter
(sprouts.Action<ComponentMouseEventDelegate<C>> onEnter) Use this to register and catch mouse enter events on theUI.ComponentArea.BODY
of this UI component,
which consists of the full component boundaries except for the surrounding margins and corner rounding areas.final I
onMouseEnter
(UI.ComponentArea area, sprouts.Action<ComponentMouseEventDelegate<C>> onEnter) Use this to register and catch mouse enter events on a specific area of this UI component, defined by the first argument, aUI.ComponentArea
enum value, and the second argument, a lambda instance which will be invoked when the mouse enters the specified area.final I
onMouseEnterGreedy
(sprouts.Action<ComponentMouseEventDelegate<C>> onEnter) Use this to register and catch simpleMouseListener
based mouse enter events on this UI component.final I
onMouseExit
(sprouts.Action<ComponentMouseEventDelegate<C>> onExit) Use this to register and catch mouse exit events on theUI.ComponentArea.BODY
of this UI component,
which consists of the full component boundaries except for the surrounding margins and corner rounding areas.final I
onMouseExit
(UI.ComponentArea area, sprouts.Action<ComponentMouseEventDelegate<C>> onExit) Use this to register and catch mouse exit events on a specific area of this UI component, by supplying aUI.ComponentArea
enum value to define the area, and aAction
lambda which will be invoked when the mouse exits the specified area, so that you can react to the event accordingly.final I
onMouseExitGreedy
(sprouts.Action<ComponentMouseEventDelegate<C>> onExit) Use this to register and catch simpleMouseListener
based mouse exit events on this UI component.final I
onMouseMove
(sprouts.Action<ComponentMouseEventDelegate<C>> onMove) Use this to register and catch genericMouseListener
based mouse move events on this UI component.final I
onMousePress
(sprouts.Action<ComponentMouseEventDelegate<C>> onPress) Use this to register and catch genericMouseListener
based mouse press events on this UI component.final I
onMouseRelease
(sprouts.Action<ComponentMouseEventDelegate<C>> onRelease) Use this to register and catch genericMouseListener
based mouse release events on this UI component.final I
onMouseWheelDown
(sprouts.Action<ComponentDelegate<C, MouseWheelEvent>> onWheelDown) Use this to register and catch mouse wheel down movement events on this UI component.final I
onMouseWheelMove
(sprouts.Action<ComponentDelegate<C, MouseWheelEvent>> onWheel) Use this to register and catch genericMouseListener
based mouse wheel events on this UI component.final I
onMouseWheelUp
(sprouts.Action<ComponentDelegate<C, MouseWheelEvent>> onWheelUp) Use this to register and catch mouse wheel up movement events on this UI component.final I
onMoved
(sprouts.Action<ComponentDelegate<C, ComponentEvent>> onMoved) The provided lambda will be invoked when the component was moved.final I
onPressed
(Keyboard.Key key, sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyPressed) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the providedKeyboard.Key
.final I
onRelease
(Keyboard.Key key, sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyReleased) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the built component receives a particular keyboard input matching the providedKeyboard.Key
.final I
onResize
(sprouts.Action<ComponentDelegate<C, ComponentEvent>> onResize) The provided lambda will be invoked when the component's size changes.final I
onShown
(sprouts.Action<ComponentDelegate<C, AncestorEvent>> onShown) Adds the suppliedAction
wrapped in aAncestorListener
to the component, to receive calls when the wrapped component becomes visible on the screen.final I
onTyped
(char character, sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyTyped) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the provided character.final I
onTyped
(Keyboard.Key key, sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyTyped) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the providedKeyboard.Key
.final <E extends sprouts.Observable>
IonView
(E observableEvent, sprouts.Action<ComponentDelegate<C, E>> action) Allows you to cause an effect inside your UI when an observable event is fired.final I
withBackground
(Color color) Use this to set the background color of the UI component wrapped by this builder.
This is in essence a convenience method, which avoid having to expose the underlying component through theUIForAnything.peek(Peeker)
method like so:final I
withBackground
(sprouts.Val<Color> bg) Use this to bind to aVal
containing a background color.final I
withBackgroundColor
(String color) Use this to set the background color of the UI component of this declarative builder using a color String.final I
withBackgroundIf
(sprouts.Val<Boolean> condition, Color colorIfTrue) Use this to bind to a background color which will be set dynamically based on a boolean property.final I
withBackgroundIf
(sprouts.Val<Boolean> condition, Color colorIfTrue, Color colorIfFalse) Use this to bind to 2 colors to the background of the component which sre set based on the value of a boolean property.final I
withBackgroundIf
(sprouts.Val<Boolean> condition, sprouts.Val<Color> color) Use this to dynamically bind to a background color which will be set dynamically based on a boolean property.final I
withBackgroundIf
(sprouts.Val<Boolean> condition, sprouts.Val<Color> colorIfTrue, sprouts.Val<Color> colorIfFalse) Use this to bind to 2 color properties to the background of the component which sre set based on the value of a boolean property.final I
withBorder
(Border border) Use this to attach a border to the wrapped component.final I
withBorder
(sprouts.Val<Border> border) Deprecated.Because changing theBorder
of a component dynamically after the component was initialized through the declarative SwingTree API, causes issues with the style engine of a component.final I
withBorderTitled
(String title) Use this to attach aTitledBorder
with the provided title.final I
withBorderTitled
(sprouts.Val<String> title) Use this to attach aTitledBorder
with the provided title property dynamically setting the title String.final I
withBoxLayout
(UI.Axis axis) Use this to set aBoxLayout
for the component wrapped by this builder.final I
withCompoundBorder
(Border first, Border second) Use this to attach aCompoundBorder
with the provided borders to theJComponent
.final I
withCompoundBorderTitled
(String title, Border first, Border second) Use this to attach a titledCompoundBorder
with the provided borders to theJComponent
.final I
withCursor
(sprouts.Val<UI.Cursor> type) Use this to dynamically set the cursor type which should be displayed when hovering over the UI component wrapped by this builder.final I
withCursor
(UI.Cursor type) Use this set the cursor type which should be displayed when hovering over the UI component wrapped by this builder.final I
withCursorIf
(sprouts.Val<Boolean> condition, sprouts.Val<UI.Cursor> type) Use this to dynamically set the cursor type which should be displayed when hovering over the UI component wrapped by this builder based on boolean property determining if the provided cursor should be set ot not.final I
withCursorIf
(sprouts.Val<Boolean> condition, UI.Cursor type) Use this to set the cursor type which should be displayed when hovering over the UI component wrapped by this builder based on boolean property determining if the provided cursor should be set ot not.final I
withDragAway
(Configurator<DragAwayComponentConf<C>> configurator) Exposes a functionalConfigurator
API for turning the component into a drag source site with the given configuration.final I
withDropSite
(Configurator<DragDropComponentConf<C>> configurator) Exposes a functionalConfigurator
API for turning the component into a drag drop receiver site with the given configuration.final I
withEmptyBorder
(int all) Use this to define an emptyBorder
with the provided insets.final I
withEmptyBorder
(int topBottom, int leftRight) Use this to define an emptyBorder
with the provided insets.final I
withEmptyBorder
(int top, int left, int bottom, int right) Use this to define an emptyBorder
with the provided insets.final I
withEmptyBorder
(sprouts.Val<Integer> all) Creates an empty and un-titledBorder
with the provided insets property bound to all insets of said border.final I
withEmptyBorderTitled
(String title) Use this to define an emptyBorder
with a title and a default insets size of 5.final I
withEmptyBorderTitled
(String title, int all) Use this to define a titled emptyBorder
with the provided insets.final I
withEmptyBorderTitled
(String title, int topBottom, int leftRight) Use this to define a titled emptyBorder
with the provided insets.final I
withEmptyBorderTitled
(String title, int top, int left, int bottom, int right) Use this to define a titled emptyBorder
with the provided insets.final I
withEmptyBorderTitled
(sprouts.Val<String> title) Creates a titled empty border bound to aString
property and a default insets size of 5.final I
withEmptyBorderTitled
(sprouts.Val<String> title, int all) Creates a titled empty border bound to aString
property and the provided insets.final I
withEmptyBorderTitled
(sprouts.Val<String> title, int topBottom, int leftRight) Use this to define a titled emptyBorder
with the provided insets and where the title is bound to aVal
.final I
withEmptyBorderTitled
(sprouts.Val<String> title, int top, int left, int bottom, int right) Use this to define a titled emptyBorder
with the provided insets and where the title is bound to aVal
.final I
Use this to set aFlowLayout
for the component wrapped by this builder.final I
withFlowLayout
(UI.HorizontalAlignment alignment) Use this to set aFlowLayout
for the component wrapped by this builder.final I
withFlowLayout
(UI.HorizontalAlignment alignment, int hgap, int vgap) Use this to set aFlowLayout
for the component wrapped by this builder.final I
withForeground
(Color color) Set the color of thisJComponent
.final I
withForeground
(sprouts.Val<Color> fg) Use this to bind to aVal
containing a foreground color.final I
withForegroundColor
(String color) Allows you to define theComponent.getForeground()
color of the underlyingJComponent
using a color string.final I
withForegroundIf
(sprouts.Val<Boolean> condition, Color fg) Use this to bind to a foreground color which will be set dynamically based on a boolean property.final I
withForegroundIf
(sprouts.Val<Boolean> condition, Color colorIfTrue, Color colorIfFalse) Use this to dynamically bind to a foreground color which will be set dynamically based on a boolean property.final I
withForegroundIf
(sprouts.Val<Boolean> condition, sprouts.Val<Color> color) Use this to dynamically bind to a foreground color which will be set dynamically based on a boolean property.final I
withForegroundIf
(sprouts.Val<Boolean> condition, sprouts.Val<Color> colorIfTrue, sprouts.Val<Color> colorIfFalse) Use this to dynamically bind to a foreground color which will be set dynamically based on a boolean property.final I
Use this to set a newGridBagLayout
for the component wrapped by this builder.final I
Use this to set aGridLayout
for the component wrapped by this builder.final I
withGridLayout
(int rows, int cols) Use this to set aGridLayout
for the component wrapped by this builder.final I
withGridLayout
(int rows, int cols, int hgap, int vgap) Use this to set aGridLayout
for the component wrapped by this builder.final I
withHeight
(int height) Set the current height of thisJComponent
.final I
withHeight
(sprouts.Val<Integer> height) Bind to aVal
object to dynamically set the current height of thisJComponent
.final I
withHeightExactly
(int height) Use this to set the min-, max- and preferred height of thisJComponent
to the same value.final I
withHeightExactly
(sprouts.Val<Integer> height) Use this to bind to aVal
property to dynamically update the min-, max- and preferred height of thisJComponent
to the same value.final I
withLayout
(LayoutManager layout) Use this to set theLayoutManager
of the component wrapped by this builder.final I
withLayout
(String attr) This creates aMigLayout
for the component wrapped by this UI builder, based on the provided layout-constraints in the form of a simple string which is parsed by theConstraintParser
class intoLC
andAC
instances.final I
withLayout
(String attr, String colConstrains) This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of a string.final I
withLayout
(String constraints, String colConstrains, String rowConstraints) This creates aMigLayout
for the component wrapped by this UI builder, based on the provided layout-, column- and row-constraints in the form of simple strings, which are parsed by theConstraintParser
class intoLC
andAC
instances.final I
withLayout
(@Nullable net.miginfocom.layout.LC attr, @Nullable net.miginfocom.layout.AC colConstrains, @Nullable net.miginfocom.layout.AC rowConstraints) This creates aMigLayout
for the component wrapped by this UI builder.final I
withLayout
(net.miginfocom.layout.LC attr) Creates a newMigLayout
for the component wrapped by this UI builder, based on the provided layout constraints in the form of aLC
instance, which is a builder for the layout constraints.final I
withLayout
(net.miginfocom.layout.LC attr, String colConstrains) This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of aLC
instance and column constraints in the form of a simple string.final I
withLayout
(net.miginfocom.layout.LC attr, String colConstrains, String rowConstraints) This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of aLC
instance and column and row constraints in the form of a simple string.final I
withLayout
(net.miginfocom.layout.LC attr, net.miginfocom.layout.AC colConstrains) This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of aLC
instance and column constraints in the form of aAC
instance.final I
withLayout
(LayoutConstraint attr) Creates a newMigLayout
for the component wrapped by this UI builder, based on the provided layout constraints in the form of aLayoutConstraint
instance, which is an immutable string wrapper for the layout constraints.final I
withLayout
(LayoutConstraint attr, String colConstrains) Takes the supplied layout constraints and column constraints uses them to construct a newMigLayout
for the component wrapped by this UI builder.final I
withLayout
(LayoutConstraint attr, String colConstrains, String rowConstraints) This creates aMigLayout
for the component wrapped by this UI builder.final I
withLineBorder
(Color color) Use this to define a lineBorder
with the provided color and a default thickness of1
.final I
withLineBorder
(Color color, int thickness) Use this to define a lineBorder
with the provided color and insets.final I
withLineBorder
(sprouts.Val<Color> color, int thickness) Creates a line border bound to aColor
property.final I
withLineBorderTitled
(String title, Color color) Use this to define a titled lineBorder
with the provided color and a default thickness of1
.final I
withLineBorderTitled
(String title, Color color, int thickness) Use this to define a titled lineBorder
with the provided color and insets.final I
withLineBorderTitled
(sprouts.Val<String> title, Color color, int thickness) Creates a titled line border bound to aString
property.final I
withLineBorderTitled
(sprouts.Val<String> title, sprouts.Val<Color> color, int thickness) final I
withMatteBorder
(Color color, int all) Use this to attach aMatteBorder
with the provided color and insets to theJComponent
.final I
withMatteBorder
(Color color, int topBottom, int leftRight) Use this to attach aMatteBorder
with the provided color and insets to theJComponent
.final I
withMatteBorder
(Color color, int top, int left, int bottom, int right) Use this to attach aMatteBorder
with the provided color and insets to theJComponent
.final I
withMatteBorderTitled
(String title, Color color, int all) Use this to attach a titledMatteBorder
with the provided color and insets to theJComponent
.final I
withMatteBorderTitled
(String title, Color color, int topBottom, int leftRight) Use this to attach a titledMatteBorder
with the provided color and insets to theJComponent
.final I
withMatteBorderTitled
(String title, Color color, int top, int left, int bottom, int right) Use this to attach a titledMatteBorder
with the provided color and insets to theJComponent
.final I
withMaxHeight
(int height) Use this to only set the maximum height of thisJComponent
.final I
withMaxHeight
(sprouts.Val<Integer> height) Use this to dynamically set only the maximum height of thisJComponent
.final I
withMaxSize
(int width, int height) Set the maximum width and height (Dimension
) of thisJComponent
.final I
withMaxSize
(Dimension size) Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
UsewithMaxSize(Size)
instead.final I
withMaxSize
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) Bind to aVal
object to dynamically set the maximum size of thisJComponent
.final I
withMaxSize
(sprouts.Val<Size> size) final I
withMaxSize
(Size size) Set the maximumSize
of thisJComponent
.final I
withMaxWidth
(int width) Use this to only set the maximum width of thisJComponent
.final I
withMaxWidth
(sprouts.Val<Integer> width) Use this to dynamically set only the maximum width of thisJComponent
.final I
withMinHeight
(int height) Use this to only set the minimum height of thisJComponent
.final I
withMinHeight
(sprouts.Val<Integer> height) Use this to dynamically set only the minimum height of thisJComponent
.final I
withMinSize
(int width, int height) Set the minimum width and heigh (Dimension
) of thisJComponent
.final I
withMinSize
(Dimension size) Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
UsewithMinSize(Size)
instead.final I
withMinSize
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) final I
withMinSize
(sprouts.Val<Size> size) final I
withMinSize
(Size size) Set the minimumSize
of thisJComponent
.final I
withMinWidth
(int width) Use this to only set the minimum width of thisJComponent
.final I
withMinWidth
(sprouts.Val<Integer> width) Use this to dynamically set only the minimum width of thisJComponent
.final I
withPrefHeight
(int height) Use this to only set the preferred height of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.final I
withPrefHeight
(sprouts.Val<Integer> height) Use this to dynamically set only the preferred height of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.final I
withPrefSize
(int width, int height) Set the preferred width and height (Dimension
) of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.final I
withPrefSize
(Dimension size) Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
Please usewithPrefSize(Size)
instead.final I
withPrefSize
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) Bind to aVal
object to dynamically set the preferredDimension
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.final I
withPrefSize
(sprouts.Val<Size> size) Bind to aVal
object to dynamically set the preferredSize
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.final I
withPrefSize
(Size size) Set the preferredSize
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.final I
withPrefWidth
(int width) Use this to only set the preferred width of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.final I
withPrefWidth
(sprouts.Val<Integer> width) Use this to dynamically set only the preferred width of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.final I
withProperty
(String key, String value) AddsString
key/value "client property" pairs to the wrapped component.final I
withRepaintOn
(sprouts.Event event) Allows you to bind anEvent
to theComponent.repaint()
method of the component represented by this builder.final I
withRepaintOn
(sprouts.Event first, sprouts.Event second, sprouts.Event... rest) This method exposes a concise way to bind multipleEvent
s to theComponent.repaint()
method of the component represented by this builder.final I
withRepaintOn
(sprouts.Observable observable) Use this to bind anObservable
(usually from a sprouts.Event) to theComponent.repaint()
method of the component represented by this builder.final I
withRepaintOn
(sprouts.Observable first, sprouts.Observable second, sprouts.Observable... rest) This method exposes a concise way to bind multipleObservable
s (usually sprouts.Event instances) to theComponent.repaint()
method of the component represented by this builder.final I
withRepaintOn
(sprouts.Val<?> event) Allows you to bind aVal
to theComponent.repaint()
method of the component represented by this builder.final I
withRepaintOn
(sprouts.Val<?> first, sprouts.Val<?> second, sprouts.Val<?>... rest) Use this method to bind multipleVal
s to theComponent.repaint()
method of the component represented by this builder.final I
final I
withRoundedLineBorder
(Color color) Use this to attach a rounded lineBorder
with the provided color and a default thickness of1
to theJComponent
.final I
withRoundedLineBorder
(Color color, int thickness) Use this to attach a rounded lineBorder
with the provided color and insets to theJComponent
.final I
withRoundedLineBorder
(sprouts.Val<Color> color, int thickness) Use this to attach a titled rounded lineBorder
with the provided color property and a custom thickness to theJComponent
.final I
final I
withRoundedLineBorderTitled
(String title, Color color) Use this to attach a titled rounded lineBorder
with the provided title, color and a default thickness of1
to theJComponent
.final I
withRoundedLineBorderTitled
(String title, Color color, int thickness) Use this to attach a titled rounded lineBorder
with the provided color and insets to theJComponent
.final I
withRoundedLineBorderTitled
(sprouts.Val<String> title) Creates a titled rounded black lineBorder
with a thickness of1
to theJComponent
and binds it to the provided title property.final I
withRoundedLineBorderTitled
(sprouts.Val<String> title, Color color, int thickness) Creates a titled rounded lineBorder
with the provided color and insets for thisJComponent
and binds the border to the provided title property.final I
withRoundedLineBorderTitled
(sprouts.Val<String> title, sprouts.Val<Color> color) Use this to attach a titled rounded lineBorder
with the provided title and color to theJComponent
, as well as a default thickness of1
.final I
withRoundedLineBorderTitled
(sprouts.Val<String> title, sprouts.Val<Color> color, int thickness) Creates a titled rounded lineBorder
with the provided color and insets for thisJComponent
and binds the border to the provided title and color properties.final I
withSize
(int width, int height) Allows you to directly set the width and height of the current component directly instead of through the layout manager.final I
Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
Please usewithSize(Size)
instead.final I
Bind to aVal
object to dynamically set the currentDimension
of thisJComponent
using aSize
object.final I
Sets the currentSize
) (width and height) of thisJComponent
.final I
withSizeExactly
(int width, int height) Allows you to define a common width and height for the minimum, maximum, and preferred size of this component.final I
withSizeExactly
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) Allows you to bind to twoVal
properties to dynamically update the common width and height for the minimum, maximum, and preferred size of this component.final I
withSizeExactly
(sprouts.Val<Size> size) Bind to aSize
object to dynamically update the common width and height for the minimum, maximum, and preferred size of this component.final I
withSizeExactly
(Size size) Allows you to define a common width and height for the minimum, maximum, and preferred size of this component in the form of the suppliedSize
object.final I
Allows you to configure how the component wrapped by this builder looks and behaves, by passing aStyler
lambda to this method which receiving aComponentStyleDelegate
and returns an updated version with the desired style rules applied.final I
withTooltip
(String tooltip) Use this to set a helpful tool tip text for this UI component.final I
withTooltip
(sprouts.Val<String> tip) Use this to bind to aVal
containing a tooltip string.final I
withTransitionalStyle
(sprouts.Val<Boolean> transitionToggle, LifeTime transitionLifeTime, AnimatedStyler<C> styler) Here an example demonstrating how a transitional style can be applied to make a border which can transition between 2 colors based on a boolean property:final I
withTransitoryStyle
(sprouts.Event styleEvent, LifeTime styleLifeTime, AnimatedStyler<C> styler) Allows you to configure a style which will be applied to the component temporarily when the providedEvent
is fired.final I
withWidth
(int width) Set the current width of thisJComponent
.final I
Bind to aVal
object to dynamically set the current width of thisJComponent
.final I
withWidthExactly
(int width) Use this to set the min-, max- and preferred width of thisJComponent
to the same value.final I
withWidthExactly
(sprouts.Val<Integer> width) Use this to bind to aVal
property to dynamically update the min-, max- and preferred width of thisJComponent
to the same value.Methods inherited from class swingtree.UIForAnything
_addBuildersTo, _addBuilderTo, _addComponentsTo, _disposeState, _newBuilderWithState, _onShow, _onShow, _runInApp, _runInApp, _runInUI, _state, _this, _with, _withOnShow, _withOnShow, add, add, add, add, apply, applyIf, applyIfPresent, component, equals, get, getComponent, getType, hashCode, peek, toString
-
Constructor Details
-
UIForAnySwing
public UIForAnySwing()
-
-
Method Details
-
_isUndefinedFont
-
_isUndefinedColor
-
withRepaintOn
Use this to bind anObservable
(usually from a sprouts.Event) to theComponent.repaint()
method of the component represented by this builder. This means that the component will be repainted whenever the source of the observable is fired or changed.- Parameters:
observable
- The observable to which the repaint method of the component will be bound.- Returns:
- This declarative builder instance, which enables builder-style method chaining.
-
withRepaintOn
public final I withRepaintOn(sprouts.Observable first, sprouts.Observable second, sprouts.Observable... rest) This method exposes a concise way to bind multipleObservable
s (usually sprouts.Event instances) to theComponent.repaint()
method of the component represented by this builder. This means that the component will be repainted whenever the source of any one of the observables is fired or changed.- Parameters:
first
- The first observable to which the repaint method of the component will be bound.second
- The second observable to which the repaint method of the component will be bound.rest
- The rest of the observables to which the repaint method of the component will be bound.- Returns:
- This declarative builder instance, which enables builder-style method chaining.
-
withRepaintOn
Allows you to bind anEvent
to theComponent.repaint()
method of the component represented by this builder.
This means that the component will be repainted whenever the event is fired through theEvent.fire()
method.- Parameters:
event
- The event to which the repaint method of the component will be bound.- Returns:
- This declarative builder instance, which enables builder-style method chaining.
-
withRepaintOn
This method exposes a concise way to bind multipleEvent
s to theComponent.repaint()
method of the component represented by this builder. This means that the component will be repainted whenever any one of the events is fired through theEvent.fire()
method.- Parameters:
first
- The first event to which the repaint method of the component will be bound.second
- The second event to which the repaint method of the component will be bound.rest
- The rest of the events to which the repaint method of the component will be bound.- Returns:
- This declarative builder instance, which enables builder-style method chaining.
-
withRepaintOn
Allows you to bind aVal
to theComponent.repaint()
method of the component represented by this builder.
This means that the component will be repainted whenever the value of theVal
changes. If theVal
is a mutableVar
property, then this event is usually triggered through theVar.set(Object)
method.
A typical use case is to use
Var
properties in theStyler
of the style API exposed bywithStyle(Styler)
, and then also pass these properties to the thiswithRepaintOn
method to ensure that the style gets re-evaluated and then repainted.- Parameters:
event
- TheVal
to which the repaint method of the component will be bound.- Returns:
- This declarative builder instance, which enables builder-style method chaining.
-
withRepaintOn
Use this method to bind multipleVal
s to theComponent.repaint()
method of the component represented by this builder. This means that the component will be repainted whenever the value of any one of theVal
s changes. If theVal
is a mutableVar
property, then this event is usually triggered through theVar.set(Object)
method.
A typical use case is to use
Var
properties in theStyler
of the style API exposed bywithStyle(Styler)
, and then also pass these properties to the thiswithRepaintOn
method to ensure that the style gets re-evaluated and then repainted.- Parameters:
first
- The firstVal
to which the repaint method of the component will be bound.second
- The secondVal
to which the repaint method of the component will be bound.rest
- The rest of theVal
s to which the repaint method of the component will be bound.- Returns:
- This declarative builder instance, which enables builder-style method chaining.
-
id
This method exposes a concise way to set an identifier for the component represented by this builder chain. In essence this is simply a delegate for theComponent.setName(String)
method to make it more expressive and widely recognized what is meant ("id" is shorter and makes more sense than "name" which could be confused with "title").- Parameters:
id
- The identifier for thisJComponent
which will simply translate toComponent.setName(String)
- Returns:
- The JComponent type which will be managed by this builder.
-
id
This method exposes a concise way to set an enum based identifier for the component represented by this builder chain. In essence this is simply a delegate for theComponent.setName(String)
method to make it more expressive and widely recognized what is meant ("id" is shorter and makes more sense than "name" which could be confused with "title").The enum identifier will be translated to a string using
Enum.name()
.- Type Parameters:
E
- The enum type.- Parameters:
id
- The enum identifier for thisJComponent
which will simply translate toComponent.setName(String)
- Returns:
- The JComponent type which will be managed by this builder.
-
group
This method is part of the SwingTree style API, and it allows you to add this component to a style group. This is conceptually similar to CSS classes, with the difference that style groups can inherit from each other insideStyleSheet
s.
Here an example of how to define styles for a style group:new StyleSheet() { @Override protected void build() { add(group("A").inherits("B", "C"), it -> it .backgroundColor(Color.RED) ); add(group("B"), it -> it .borderWidth(12) ); add(group("C"), it -> it .borderWidth(16) .borderColor(Color.YELLOW) ); } }
The style sheet in the above example code can be applied to a component like so:UI.use(new MyStyleSheet(), ()-> UI.button("Click me").group("A") .onClick(it -> {...}) );
It is advised to use thegroup(Enum[])
method instead of this method, as the usage of enums for modelling group tags offers much better compile time type safety!- Parameters:
groupTags
- The names of the style groups to which this component should be added.- Returns:
- This very instance, which enables builder-style method chaining.
-
group
This method is part of the SwingTree style API, and it allows you to add this component to an enum based style group. This is conceptually similar to CSS classes, with the difference that style groups can inherit from each other insideStyleSheet
s.
Here an example of how to define styles for a style group:new StyleSheet() { @Override protected void build() { add(group(MyGroups.A).inherits("B", "C"), it -> it .backgroundColor(Color.RED) ); add(group(MyGroups.B), it -> it .borderWidth(12) ); add(group(MyGroups.C), it -> it .borderWidth(16) .borderColor(Color.YELLOW) ); } }
The style sheet in the above example code can be applied to a component like so:UI.use(new MyStyleSheet(), ()-> UI.button("Click me").group(MyGroup.A) .onClick(it -> {...}) );
- Type Parameters:
E
- The enum type.- Parameters:
groupTags
- The enum based style group to which this component should be added.- Returns:
- This very instance, which enables builder-style method chaining.
-
isVisibleIf
Make the underlyingJComponent
type visible or invisible depending on the supplied boolean value.- Parameters:
isVisible
- The truth value determining if the component should be visible or not.- Returns:
- This very instance, which enables builder-style method chaining.
-
isVisibleIfNot
This is the inverse ofisVisibleIf(boolean)
, and it is used to make the underlyingJComponent
type visible or invisible.If the supplied boolean value is
true
, the component will be invisible.
If the supplied boolean value isfalse
, the component will be visible.- Parameters:
isVisible
- The truth value determining if the UI component should be visible or not.- Returns:
- This very instance, which enables builder-style method chaining.
-
isVisibleIf
Make the underlyingJComponent
type dynamically visible or invisible through the suppliedVal
property, which is automatically bound to theJComponent.setVisible(boolean)
method of the underlyingJComponent
type.This means that when the supplied
Val
property changes its value, then visibility of the underlyingJComponent
type will be updated accordingly.Hint: Use
myProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
isVisible
- The truth value determining if the UI component should be visible or not wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
isVisibleIfNot
This is the inverse ofisVisibleIf(Val)
, and it is used to make the underlyingJComponent
type dynamically visible or invisible.This means that when the supplied
Val
property changes its value, then visibility of the underlyingJComponent
type will be updated accordingly.If the supplied
Val
property istrue
, the component will be invisible.
If the suppliedVal
property isfalse
, the component will be visible.Hint: Use
myProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
isVisible
- The truth value determining if the UI component should be visible or not wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
isVisibleIf
Make the underlyingJComponent
type dynamically visible or invisible based on the equality between the supplied enum value and enum property.
This means that when the supplied
Val
property changes its value, and the new value is equal to the supplied enum value, then the underlyingJComponent
type will be visible, otherwise it will be invisible. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Type Parameters:
E
- The enum type.- Parameters:
enumValue
- The enum value which, if equal to the supplied enum property, makes the UI component visible.enumProperty
- The enum property which, if equal to the supplied enum value, makes the UI component visible.- Returns:
- This very instance, which enables builder-style method chaining.
-
isVisibleIfNot
This is the inverse ofisVisibleIf(Enum, Val)
, and it is used to make the underlyingJComponent
type dynamically visible or invisible.This means that when the supplied
Val
property changes its value, and the new value is equal to the supplied enum value, then the underlyingJComponent
type will be invisible, otherwise it will be visible. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Type Parameters:
E
- The enum type for both the supplied enum value and enum property.- Parameters:
enumValue
- The enum value which, if equal to the supplied enum property, makes the UI component invisible.enumProperty
- The enum property which, if equal to the supplied enum value, makes the UI component invisible.- Returns:
- This very instance, which enables builder-style method chaining.
-
isEnabledIf
Use this to enable or disable the wrapped UI component.- Parameters:
isEnabled
- The truth value determining if the UI component should be enabled or not.- Returns:
- This very instance, which enables builder-style method chaining.
-
isEnabledIfNot
This is the inverse ofisEnabledIf(boolean)
. Use this to disable or enable the wrapped UI component.- Parameters:
isEnabled
- The truth value determining if the UI component should be enabled or not.- Returns:
- This very instance, which enables builder-style method chaining.
-
isEnabledIf
Use this to dynamically enable or disable the wrapped UI component.- Parameters:
isEnabled
- The truth value determining if the UI component should be enabled or not wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
isEnabledIfNot
This is the inverse ofisEnabledIf(Val)
. Use this to dynamically disable or enable the wrapped UI component.- Parameters:
isEnabled
- The truth value determining if the UI component should be enabled or not wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
isEnabledIf
Use this to make the wrapped UI component dynamically enabled or disabled, based on the equality between the supplied enum value and enum property.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Type Parameters:
E
- The enum type for both the supplied enum value and enum property.- Parameters:
enumValue
- The enum value which, if equal to the supplied enum property, makes the UI component enabled.enumProperty
- The enum property which, if equal to the supplied enum value, makes the UI component enabled.- Returns:
- This very instance, which enables builder-style method chaining.
-
isEnabledIfNot
This is the inverse ofisEnabledIf(Enum, Val)
. Use this to make the wrapped UI component dynamically disabled or enabled, based on the equality between the supplied enum value and enum property.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Type Parameters:
E
- The enum type for both the supplied enum value and enum property.- Parameters:
enumValue
- The enum value which, if equal to the supplied enum property, makes the UI component disabled.enumProperty
- The enum property which, if equal to the supplied enum value, makes the UI component disabled.- Returns:
- This very instance, which enables builder-style method chaining.
-
_setEnabled
-
makeFocused
Use this to make the wrapped UI component grab the input focus.- Returns:
- This very instance, which enables builder-style method chaining.
-
isFocusableIf
Use this to make the wrapped UI component focusable.- Parameters:
isFocusable
- The truth value determining if the UI component should be focusable or not.- Returns:
- This very instance, which enables builder-style method chaining.
-
isFocusableIf
Use this to dynamically make the wrapped UI component focusable. This is useful if you want to make a component focusable only if a certain condition is met.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
isFocusable
- The truth value determining if the UI component should be focusable or not wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
isFocusableIfNot
Use this to make the wrapped UI component focusable if a certain condition is not met.- Parameters:
notFocusable
- The truth value determining if the UI component should be focusable or not. Iffalse
, the component will be focusable.- Returns:
- This very instance, which enables builder-style method chaining.
-
isFocusableIfNot
Use this to dynamically make the wrapped UI component focusable. This is useful if you want to make a component focusable only if a certain condition is met.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
isFocusable
- The truth value determining if the UI component should be focusable or not, wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- if the suppliedisFocusable
isnull
.
-
isFocusableIf
Use this to make the wrapped UI component dynamically focusable or non-focusable based on the equality between the supplied enum value and enum property.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Type Parameters:
E
- The enum type for both the supplied enum value and enum property.- Parameters:
enumValue
- The enum value which, if equal to the supplied enum property, makes the UI component focusable.enumProperty
- The enum property which, if equal to the supplied enum value, makes the UI component focusable.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- if the suppliedenumValue
orenumProperty
isnull
.
-
isFocusableIfNot
This is the inverse ofisFocusableIf(Enum, Val)
. Use this to make the wrapped UI component dynamically focusable or non-focusable based on the equality between the supplied enum value and enum property.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Type Parameters:
E
- The enum type for both the supplied enum value and enum property.- Parameters:
enumValue
- The enum value which, if equal to the supplied enum property, makes the UI component non-focusable.enumProperty
- The enum property which, if equal to the supplied enum value, makes the UI component non-focusable.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- if the suppliedenumValue
orenumProperty
isnull
.
-
makeOpaque
Deprecated.SwingTree considers the opaqueness a property which emerges from the style configuration of the component. Therefore, it is not recommended to set the opaqueness directly. Instead, use thewithBackground(Color)
method to set the style of the component so that it becomes opaque.Use this to make the wrapped UI component opaque. This is the inverse ofmakeNonOpaque()
.- Returns:
- This very instance, which enables builder-style method chaining.
-
makeNonOpaque
Deprecated.UsewithBackground(Color)
instead, by passing it theUI.Color.TRANSPARENT
constant.
Alternatively, you may use theUIForAnything.peek(Peeker)
method to peek into the builder's component and set the flag directly.Use this to make the wrapped UI component transparent. This is the inverse ofmakeOpaque()
.- Returns:
- This very instance, which enables builder-style method chaining.
-
isValidIf
This allows you to register validation logic for the wrapped UI component. Although the delegate exposed to theUIVerifier
lambda indirectly exposes you to the UIs state, you should not access the UI directly from within the lambda, but modify the properties inside your view model instead.- Parameters:
verifier
- The validation logic provided by your view model.- Returns:
- This very instance, which enables builder-style method chaining.
-
withProperty
AddsString
key/value "client property" pairs to the wrapped component.The arguments will be passed to
JComponent.putClientProperty(Object, Object)
which accesses a small per-instance hashtable. Callers can use get/putClientProperty to annotate components that were created by another module. For example, a layout manager might store per child constraints this way.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.button() .peek( button -> button.putClientProperty("key", "value") );
- Parameters:
key
- the new client property key which may be used for styles or layout managers.value
- the new client property value.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBorder
Use this to attach a border to the wrapped component.- Parameters:
border
- TheBorder
which should be set for the wrapped component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBorder
Deprecated.Because changing theBorder
of a component dynamically after the component was initialized through the declarative SwingTree API, causes issues with the style engine of a component. (Which itself is based on using a custom border for style rendering)Use this to dynamically attach a border to the wrapped component.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
border
- TheBorder
which should be set for the wrapped component wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorder
Use this to define an emptyBorder
with the provided insets.- Parameters:
top
- The top inset.left
- The left inset.bottom
- The bottom inset.right
- The right inset.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Use this to define a titled emptyBorder
with the provided insets.- Parameters:
title
- The title of the border.top
- The top inset.left
- The left inset.bottom
- The bottom inset.right
- The right inset.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
public final I withEmptyBorderTitled(sprouts.Val<String> title, int top, int left, int bottom, int right) Use this to define a titled emptyBorder
with the provided insets and where the title is bound to aVal
.- Parameters:
title
- The title of the border wrapped in aVal
, which will update the border title dynamically when changed.top
- The top inset.left
- The left inset.bottom
- The bottom inset.right
- The right inset.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorder
Use this to define an emptyBorder
with the provided insets.- Parameters:
topBottom
- The top and bottom insets.leftRight
- The left and right insets.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Use this to define a titled emptyBorder
with the provided insets.- Parameters:
title
- The title of the border.topBottom
- The top and bottom insets.leftRight
- The left and right insets.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Use this to define a titled emptyBorder
with the provided insets and where the title is bound to aVal
.- Parameters:
title
- The title of the border wrapped in aVal
. When the value changes, the border title will be updated.topBottom
- The top and bottom insets.leftRight
- The left and right insets.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorder
Use this to define an emptyBorder
with the provided insets.- Parameters:
all
- The insets for all sides.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorder
Creates an empty and un-titledBorder
with the provided insets property bound to all insets of said border.An empty and un-titled
Border
is basically just a way to add some space around the component. It is not visible by default.- Parameters:
all
- The insets for all sides.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Use this to define a titled emptyBorder
with the provided insets.- Parameters:
title
- The title of the border.all
- The insets for all sides.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Creates a titled empty border bound to aString
property and the provided insets.- Parameters:
title
- The title of the border in the form of aVal
property.all
- The insets size for all sides.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Use this to define an emptyBorder
with a title and a default insets size of 5.- Parameters:
title
- The title of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withEmptyBorderTitled
Creates a titled empty border bound to aString
property and a default insets size of 5.- Parameters:
title
- The title of the border in the form of aVal
property.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorder
Use this to define a lineBorder
with the provided color and insets.- Parameters:
color
- The color of the line border.thickness
- The thickness of the line border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorder
Creates a line border bound to aColor
property. When the color changes, the border will be updated with the new color.- Parameters:
color
- The color of the border in the form of aVal
property.thickness
- The thickness of the line border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorderTitled
Use this to define a titled lineBorder
with the provided color and insets.- Parameters:
title
- The title of the border.color
- The color of the line border.thickness
- The thickness of the line border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorderTitled
Creates a titled line border bound to aString
property.- Parameters:
title
- The title property of the border which will update the border when the value changes.color
- The color of the border.thickness
- The thickness of the line border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorderTitled
public final I withLineBorderTitled(sprouts.Val<String> title, sprouts.Val<Color> color, int thickness) Creates a titled line border bound to aString
property and aColor
property. When any of the properties change, the border will be updated with the new values.- Parameters:
title
- The title property of the border which will update the border when the value changes.color
- The color property of the border which will update the border when the value changes.thickness
- The thickness of the line border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorder
Use this to define a lineBorder
with the provided color and a default thickness of1
.- Parameters:
color
- The color of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLineBorderTitled
Use this to define a titled lineBorder
with the provided color and a default thickness of1
.- Parameters:
title
- The title of the border.color
- The color of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorder
Use this to attach a rounded lineBorder
with the provided color and insets to theJComponent
.- Parameters:
color
- The color of the border.thickness
- The thickness of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
Use this to attach a titled rounded lineBorder
with the provided color and insets to theJComponent
.- Parameters:
title
- The title of the border.color
- The color of the border.thickness
- The thickness of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
Creates a titled rounded lineBorder
with the provided color and insets for thisJComponent
and binds the border to the provided title property. When the title property changes, the border will be updated with the new value.- Parameters:
title
- The title property of the border which will update the border when the value changes.color
- The color of the border.thickness
- The thickness of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
public final I withRoundedLineBorderTitled(sprouts.Val<String> title, sprouts.Val<Color> color, int thickness) Creates a titled rounded lineBorder
with the provided color and insets for thisJComponent
and binds the border to the provided title and color properties. When the title or color properties change, then the border will be updated with the new values.- Parameters:
title
- The title property of the border which will update the border when the value changes.color
- The color property of the border which will update the border when the value changes.thickness
- The thickness of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorder
Use this to attach a rounded lineBorder
with the provided color and a default thickness of1
to theJComponent
.- Parameters:
color
- The color of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorder
Use this to attach a titled rounded lineBorder
with the provided color property and a custom thickness to theJComponent
.- Parameters:
color
- The color of the border.thickness
- The thickness of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
Use this to attach a titled rounded lineBorder
with the provided title, color and a default thickness of1
to theJComponent
.- Parameters:
title
- The title of the border.color
- The color of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
Use this to attach a titled rounded lineBorder
with the provided title and color to theJComponent
, as well as a default thickness of1
.- Parameters:
title
- The title property of the border, which will update the border when the property changes.color
- The color property of the border, which will update the border when the property changes.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorder
- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
- Parameters:
title
- The title of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withRoundedLineBorderTitled
Creates a titled rounded black lineBorder
with a thickness of1
to theJComponent
and binds it to the provided title property. When the property changes, the border will be updated.- Parameters:
title
- The title property of the border, which will update the border when the property changes.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMatteBorder
Use this to attach aMatteBorder
with the provided color and insets to theJComponent
.- Parameters:
color
- The color of the border.top
- The top inset.left
- The left inset.bottom
- The bottom inset.right
- The right inset.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMatteBorderTitled
public final I withMatteBorderTitled(String title, Color color, int top, int left, int bottom, int right) Use this to attach a titledMatteBorder
with the provided color and insets to theJComponent
.- Parameters:
title
- The title of the border.color
- The color of the border.top
- The top inset.left
- The left inset.bottom
- The bottom inset.right
- The right inset.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMatteBorder
Use this to attach aMatteBorder
with the provided color and insets to theJComponent
.- Parameters:
color
- The color of the border.topBottom
- The top and bottom insets.leftRight
- The left and right insets.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMatteBorderTitled
Use this to attach a titledMatteBorder
with the provided color and insets to theJComponent
.- Parameters:
title
- The title of the border.color
- The color of the border.topBottom
- The top and bottom insets.leftRight
- The left and right insets.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMatteBorder
Use this to attach aMatteBorder
with the provided color and insets to theJComponent
.- Parameters:
color
- The color of the border.all
- The insets for all sides.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMatteBorderTitled
Use this to attach a titledMatteBorder
with the provided color and insets to theJComponent
.- Parameters:
title
- The title of the border.color
- The color of the border.all
- The insets for all sides.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCompoundBorder
Use this to attach aCompoundBorder
with the provided borders to theJComponent
.- Parameters:
first
- The first border.second
- The second border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCompoundBorderTitled
Use this to attach a titledCompoundBorder
with the provided borders to theJComponent
.- Parameters:
title
- The title of the border.first
- The first border.second
- The second border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBorderTitled
Use this to attach aTitledBorder
with the provided title.- Parameters:
title
- The title of the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBorderTitled
Use this to attach aTitledBorder
with the provided title property dynamically setting the title String.- Parameters:
title
- The title property for the border.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCursor
Use this set the cursor type which should be displayed when hovering over the UI component wrapped by this builder.
Here an example of how to use this method:UI.button("Click me!").withCursor(UI.Cursor.HAND);
- Parameters:
type
- TheUI.Cursor
type defined by a simple enum exposed by this API.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCursor
Use this to dynamically set the cursor type which should be displayed when hovering over the UI component wrapped by this builder.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
type
- TheUI.Cursor
type defined by a simple enum exposed by this API wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCursorIf
Use this to set the cursor type which should be displayed when hovering over the UI component wrapped by this builder based on boolean property determining if the provided cursor should be set ot not.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The boolean property determining if the provided cursor should be set ot not.type
- TheUI.Cursor
type defined by a simple enum exposed by this API wrapped in aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCursorIf
Use this to dynamically set the cursor type which should be displayed when hovering over the UI component wrapped by this builder based on boolean property determining if the provided cursor should be set ot not.
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The boolean property determining if the provided cursor should be set ot not.type
- TheUI.Cursor
type property defined by a simple enum exposed by this API.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLayout
Use this to set theLayoutManager
of the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new FavouriteLayoutManager()) );
- Parameters:
layout
- TheLayoutManager
which should be supplied to the wrapped component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withFlowLayout
Use this to set aFlowLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new FlowLayout()) );
- Returns:
- This very instance, which enables builder-style method chaining.
-
withFlowLayout
Use this to set aFlowLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new FlowLayout(alignment.forFlowLayout())) );
- Parameters:
alignment
- The alignment of the layout.- Returns:
- This very instance, which enables builder-style method chaining.
-
withFlowLayout
Use this to set aFlowLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new FlowLayout(alignment.forFlowLayout(), hgap, vgap)) );
- Parameters:
alignment
- The alignment of the layout.hgap
- The horizontal gap between components.vgap
- The vertical gap between components.- Returns:
- This very instance, which enables builder-style method chaining.
-
withGridLayout
Use this to set aGridLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new GridLayout()) );
- Returns:
- This very instance, which enables builder-style method chaining.
-
withGridBagLayout
Use this to set a newGridBagLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
...or specifying the layout manager like so:UI.panel() .peek( panel -> panel.setLayout(new GridBagLayout()) );
UI.panel().withLayout( new GridBagLayout() );
- Returns:
- This very instance, which enables builder-style method chaining.
-
withGridLayout
Use this to set aGridLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new GridLayout(rows, cols)) );
- Parameters:
rows
- The number of rows in the grid.cols
- The number of columns in the grid.- Returns:
- This very instance, which enables builder-style method chaining.
-
withGridLayout
Use this to set aGridLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new GridLayout(rows, cols, hgap, vgap)) );
- Parameters:
rows
- The number of rows in the grid.cols
- The number of columns in the grid.hgap
- The horizontal gap between cells.vgap
- The vertical gap between cells.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBoxLayout
Use this to set aBoxLayout
for the component wrapped by this builder.
This is in essence a more convenient way than the alternative usage pattern involving theUIForAnything.peek(Peeker)
method to peek into the builder's component like so:
UI.panel() .peek( panel -> panel.setLayout(new BoxLayout(panel, axis.forBoxLayout())) );
- Parameters:
axis
- The axis for the box layout.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If the provided axis isnull
.- See Also:
-
withLayout
This creates aMigLayout
for the component wrapped by this UI builder, based on the provided layout-constraints in the form of a simple string which is parsed by theConstraintParser
class intoLC
andAC
instances. (also seewithLayout(LC, AC, AC)
)
A typical usage pattern would be like so:
In this example a newUI.of(new MyCustomPanel()) .withLayout("fill wrap 2"); .add( UI.button("Name:") ) .add( UI.textArea() ) .add(...) ...
MigLayout
is created which will wrap the components in the layout grid after 2 columns and fill the entire available space of the parent container.
Note that if not explicitly specified, the defaulthidemode
will be set to 2, which means that when a component is hidden, it will not take up any space and the gaps around it will be collapsed.
Here an overview of the available hidemode values:- 0:
Invisible components will be handled exactly as if they were visible. - 1:
The size of the component (if invisible) will be set to 0, 0. - 2 (SwingTree default):
The size of the component (if invisible) will be set to 0, 0 and the gaps will also be set to 0 around it. - 3:
Invisible components will not participate in the layout at all and it will for instance not take up a grid cell.
- Parameters:
attr
- The constraints concerning the entire layout. Passingnull
will result in an exception, use an empty string instead.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
- 0:
-
withLayout
Creates a newMigLayout
for the component wrapped by this UI builder, based on the provided layout constraints in the form of aLC
instance, which is a builder for the layout constraints.- Parameters:
attr
- A string defining the constraints concerning the entire layout.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
-
withLayout
Creates a newMigLayout
for the component wrapped by this UI builder, based on the provided layout constraints in the form of aLayoutConstraint
instance, which is an immutable string wrapper for the layout constraints. Instances of this are usually obtained from theUI
namespace likeUILayoutConstants.FILL
orUILayoutConstants.FILL_X
...- Parameters:
attr
- Essentially an immutable string wrapper defining the mig layout.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.
-
withLayout
This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of a string.- Parameters:
attr
- A string defining constraints for the entire layout.colConstrains
- The layout constraints for the columns int theMigLayout
instance.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
-
withLayout
This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of aLC
instance and column constraints in the form of aAC
instance.- Parameters:
attr
- The constraints for the layout, aLC
instance.colConstrains
- The column layout for theMigLayout
instance as aAC
instance.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
-
withLayout
This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of aLC
instance and column constraints in the form of a simple string.- Parameters:
attr
- The constraints for the layout, aLC
instance.colConstrains
- The column layout for theMigLayout
instance as a simple string.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
-
withLayout
public final I withLayout(net.miginfocom.layout.LC attr, String colConstrains, String rowConstraints) This creates aMigLayout
for the component wrapped by this UI builder based on the provided layout constraints in the form of aLC
instance and column and row constraints in the form of a simple string.- Parameters:
attr
- The constraints for the layout, aLC
instance.colConstrains
- The column layout for theMigLayout
instance as a simple string.rowConstraints
- The row layout for theMigLayout
instance as a simple string.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
-
withLayout
Takes the supplied layout constraints and column constraints uses them to construct a newMigLayout
for the component wrapped by this UI builder.- Parameters:
attr
- The constraints for the layout.colConstrains
- The column layout for theMigLayout
instance.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
-
withLayout
This creates aMigLayout
for the component wrapped by this UI builder.- Parameters:
attr
- The constraints for the layout in the form of aLayoutConstraint
instance.colConstrains
- The column layout for theMigLayout
instance.rowConstraints
- The row layout for theMigLayout
instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
withLayout
This creates aMigLayout
for the component wrapped by this UI builder, based on the provided layout-, column- and row-constraints in the form of simple strings, which are parsed by theConstraintParser
class intoLC
andAC
instances. (also seewithLayout(LC, AC, AC)
)
A typical usage pattern would be like so:
In this example a newUI.of(new MyCustomPanel()) .withLayout("wrap 2", "[]6[]", "[]8[]"); .add( UI.label("Name:") ) .add( UI.textField() ) .add(...) ...
MigLayout
is created which will wrap the components in the layout grid after 2 columns, where the 2 columns are separated by a 6 pixel gap and the rows are separated by an 8 pixel gap.
Note that if not explicitly specified, the defaulthidemode
will be set to 2, which means that when a component is hidden, it will not take up any space and the gaps around it will be collapsed.
Here an overview of the available hidemode values:- 0:
Invisible components will be handled exactly as if they were visible. - 1:
The size of the component (if invisible) will be set to 0, 0. - 2 (SwingTree default):
The size of the component (if invisible) will be set to 0, 0 and the gaps will also be set to 0 around it. - 3:
Invisible components will not participate in the layout at all and it will for instance not take up a grid cell.
- Parameters:
constraints
- The constraints concerning the entire layout. Passingnull
will result in an exception, use an empty string instead.colConstrains
- The column layout for theMigLayout
instance, which concern the columns in the layout grid. Passingnull
will result in an exception, use an empty string instead.rowConstraints
- The row layout for theMigLayout
instance, which concern the rows in the layout grid. Passingnull
will result in an exception, use an empty string instead.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException
- If any of the arguments arenull
.- See Also:
- 0:
-
withLayout
public final I withLayout(@Nullable net.miginfocom.layout.LC attr, @Nullable net.miginfocom.layout.AC colConstrains, @Nullable net.miginfocom.layout.AC rowConstraints) This creates aMigLayout
for the component wrapped by this UI builder.- Parameters:
attr
- The constraints for the layout.colConstrains
- The column layout for theMigLayout
instance.rowConstraints
- The row layout for theMigLayout
instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
withTooltip
Use this to set a helpful tool tip text for this UI component. The tool tip text will be displayed when the mouse hovers on the UI component for some time.
This is in essence a convenience method, which avoid having to expose the underlying component through theUIForAnything.peek(Peeker)
method like so:
UI.button("Click Me") .peek( button -> button.setToolTipText("Can be clicked!") );
- Parameters:
tooltip
- The tool tip text which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withTooltip
Use this to bind to aVal
containing a tooltip string. This is a convenience method, which would be equivalent to:UI.button("Click Me") .peek( button -> { tip.onSetItem(JButton::setToolTipText); button.setToolTipText(tip.get()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
tip
- The tooltip which should be displayed when hovering over the tab header.- Returns:
- A new
Tab
instance with the provided argument, which enables builder-style method chaining.
-
withBackground
Use this to set the background color of the UI component wrapped by this builder.
This is in essence a convenience method, which avoid having to expose the underlying component through theUIForAnything.peek(Peeker)
method like so:
UI.label("Something") .peek( label -> label.setBackground(Color.CYAN) );
- Parameters:
color
- The background color which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBackgroundColor
Use this to set the background color of the UI component of this declarative builder using a color String. The suppliedString
is parsed to aUI.Color
through theUIFactoryMethods.color(String)
method.
This is in essence a convenience method, which avoid having to expose the underlying component through theUIForAnything.peek(Peeker)
method like so:
UI.label("Something") .peek( label -> label.setBackground(UI.color("cyan")) );
- Parameters:
color
- A color string which should be parsed to aUI.Color
instance and then set as the background color of the UI component.- Returns:
- A new reference to this type of builder, to allow for fluent method chaining.
-
_setBackground
-
withBackground
Use this to bind to aVal
containing a background color. This is a convenience method, which would be equivalent to:UI.button("Click Me") .peek( button -> { bg.onSetItem(JButton::setBackground); button.setBackground(bg.get()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
bg
- The background color which should be set for the UI component wrapped by aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBackgroundIf
Use this to bind to a background color which will be set dynamically based on a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the background color should be set or not.colorIfTrue
- The background color which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBackgroundIf
Use this to dynamically bind to a background color which will be set dynamically based on a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the background color should be set or not.color
- The background color property which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBackgroundIf
public final I withBackgroundIf(sprouts.Val<Boolean> condition, Color colorIfTrue, Color colorIfFalse) Use this to bind to 2 colors to the background of the component which sre set based on the value of a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the background color should be set or not.colorIfTrue
- The background color which should be set for the UI component.colorIfFalse
- The background color which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withBackgroundIf
public final I withBackgroundIf(sprouts.Val<Boolean> condition, sprouts.Val<Color> colorIfTrue, sprouts.Val<Color> colorIfFalse) Use this to bind to 2 color properties to the background of the component which sre set based on the value of a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the background color should be set or not.colorIfTrue
- The background color which should be set for the UI component.colorIfFalse
- The background color which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withStyle
Allows you to configure how the component wrapped by this builder looks and behaves, by passing aStyler
lambda to this method which receiving aComponentStyleDelegate
and returns an updated version with the desired style rules applied.Here a typical example of how to style a button using the style API:
UI.button("Click Me!") .withStyle( it -> it .borderColor(Color.CYAN) .borderWidthAt(Edge.BOTTOM, 3) .borderRadius(10) )
Here the
it
variable is theComponentStyleDelegate
which exposes an extensive API for configuring how a particular component looks and behaves.If you want to define style rules for an entire GUI or a part of it, take a look at the
StyleSheet
class, which exposes an API for defining style rules similar to CSS but based on declarative source code instead of a text file.- Parameters:
styler
- AStyler
lambda can define a set of style rules for the component wrapped by this builder by receiving aComponentStyleDelegate
and returning an updated version with the desired style rules applied.- Returns:
- This very instance, which enables builder-style method chaining.
-
withTransitionalStyle
public final I withTransitionalStyle(sprouts.Val<Boolean> transitionToggle, LifeTime transitionLifeTime, AnimatedStyler<C> styler) Here an example demonstrating how a transitional style can be applied to make a border which can transition between 2 colors based on a boolean property:UI.button("Click Me!") .withTransitionalStyle(vm.isError(), LifeTime.of(1, TimeUnit.SECONDS), (state, it) -> it .backgroundColor(Color.CYAN) .border(3, new Color((int)(state.progress() * 255), 0, 0)) )
- Parameters:
transitionToggle
- The booleanVal
property which determines the state to which the style should transition. When the value of this property istrue
, the style will transition to aAnimationStatus.progress()
of1.0
over the providedLifeTime
. And when the value of this property isfalse
, the style will transition to aAnimationStatus.progress()
of0.0
over the providedLifeTime
.transitionLifeTime
- TheLifeTime
of the transition animation. It defines for ow long theAnimationStatus.progress()
will transition from0
to1
or vice versa.styler
- AnAnimatedStyler
lambda can define a set of style rules for the component wrapped by this builder by receiving anAnimationStatus
and aComponentStyleDelegate
and returning an updated version with the desired style rules applied. TheAnimatedStyler
may apply the style properties according to theAnimationStatus
and itsAnimationStatus.progress()
method (or other methods) to create a smooth transition between the 2 states.- Returns:
- This builder instance, which enables fluent method chaining.
- See Also:
-
withTransitoryStyle
public final I withTransitoryStyle(sprouts.Event styleEvent, LifeTime styleLifeTime, AnimatedStyler<C> styler) Allows you to configure a style which will be applied to the component temporarily when the providedEvent
is fired. The style will be applied for the providedLifeTime
and then removed again. Here an example demonstrating how an event based style animation which temporarily defines a custom background and border color on a label:UI.label("I have a highlight animation!") .withTransitoryStyle(vm.highlightEvent(), LifeTime.of(0.5, TimeUnit.SECONDS), (state, it) -> it .backgroundColor(new Color(0, 0, 0, (int)(state.progress() * 255))) .borderColor(new Color(255, 255, 255, (int)(state.progress() * 255))) )
- Parameters:
styleEvent
- TheEvent
which should trigger the style animation.styleLifeTime
- TheLifeTime
of the style animation.styler
- AnAnimatedStyler
lambda can define a set of style rules for the component wrapped by this builder by receiving anAnimationStatus
and aComponentStyleDelegate
and returning an updated version with the desired style rules applied. TheAnimatedStyler
may apply the style properties according to theAnimationStatus
and itsAnimationStatus.progress()
method (or other methods) to create a smooth transition between the 2 states.- Returns:
- This builder instance, which enables fluent method chaining.
- See Also:
-
withForeground
Set the color of thisJComponent
. (This is usually the font color for components displaying text)
This is in essence a convenience method, which avoid having to expose the underlying component through theUIForAnything.peek(Peeker)
method like so:
UI.label("Something") .peek( label -> label.setForeground(Color.GRAY) );
- Parameters:
color
- The color of the foreground (usually text).- Returns:
- This very builder to allow for method chaining.
-
withForegroundColor
Allows you to define theComponent.getForeground()
color of the underlyingJComponent
using a color string. The suppliedString
is parsed to aUI.Color
through theUIFactoryMethods.color(String)
method for you.
This is in essence a convenience method, which avoid having to expose the underlying component through theUIForAnything.peek(Peeker)
method like so:
UI.label("Something") .peek( label -> label.setForeground(UI.color("oak")) );
- Parameters:
color
- A color string which should be parsed to aUI.Color
instance and then set as the foreground color of the UI component.- Returns:
- A new reference to this type of builder, to allow for fluent method chaining.
-
withForeground
Use this to bind to aVal
containing a foreground color. This is a convenience method, which works similar to:UI.button("Click Me") .peek( button -> { fg.onChange(From.VIEW_MODEL, v -> button.setForeground(v.get()) ); button.setForeground(fg.get()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
fg
- The foreground color which should be set for the UI component wrapped by aVal
.- Returns:
- This very instance, which enables builder-style method chaining.
-
withForegroundIf
Use this to bind to a foreground color which will be set dynamically based on a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the foreground color should be set or not.fg
- The foreground color which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withForegroundIf
Use this to dynamically bind to a foreground color which will be set dynamically based on a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the foreground color should be set or not.color
- The foreground color property which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withForegroundIf
public final I withForegroundIf(sprouts.Val<Boolean> condition, Color colorIfTrue, Color colorIfFalse) Use this to dynamically bind to a foreground color which will be set dynamically based on a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the foreground color should be set or not.colorIfTrue
- The foreground color which should be set for the UI component.colorIfFalse
- The foreground color which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withForegroundIf
public final I withForegroundIf(sprouts.Val<Boolean> condition, sprouts.Val<Color> colorIfTrue, sprouts.Val<Color> colorIfFalse) Use this to dynamically bind to a foreground color which will be set dynamically based on a boolean property. Hint: UsemyProperty.fire(From.VIEW_MODEL)
in your view model to send the property value to this view component.- Parameters:
condition
- The condition property which determines whether the foreground color should be set or not.colorIfTrue
- The foreground color property which should be set for the UI component.colorIfFalse
- The foreground color property which should be set for the UI component.- Returns:
- This very instance, which enables builder-style method chaining.
-
withMinSize
Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
UsewithMinSize(Size)
instead.Set the minimumDimension
of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component.- Parameters:
size
- The minimumDimension
of the component.- Returns:
- This very builder to allow for method chaining.
-
withMinSize
Set the minimumSize
of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component.- Parameters:
size
- The minimumSize
of the component.- Returns:
- This very builder to allow for method chaining.
-
withMinSize
Bind to aVal
object to dynamically set the maximumSize
of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
(Dimension)} on the underlying component.
This is a convenience method, which would be equivalent to:UI.button("Click Me") .peek( button -> { size.onSetItem(JButton::setMinimumSize); button.setMinimumSize(size.get()); });
- Parameters:
size
- The minimumSize
of the component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withMinSize
Set the minimum width and heigh (Dimension
) of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component.- Parameters:
width
- The minimum width of the component.height
- The minimum height of the component.- Returns:
- This very builder to allow for method chaining.
-
withMinSize
Bind to aVal
object to dynamically set the minimumDimension
of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component.- Parameters:
width
- The minimum width of the component.height
- The minimum height of the component.- Returns:
- This very builder to allow for method chaining.
-
withMinWidth
Use this to only set the minimum width of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component for you.- Parameters:
width
- The minimum width which should be set for the underlying component.- Returns:
- This very builder to allow for method chaining.
-
_setMinWidth
-
withMinWidth
Use this to dynamically set only the minimum width of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component for you.- Parameters:
width
- The minimum width which should be set for the underlying component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withMinHeight
Use this to only set the minimum height of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component for you.- Parameters:
height
- The minimum height which should be set for the underlying component.- Returns:
- This very builder to allow for method chaining.
-
_setMinHeight
-
withMinHeight
Use this to dynamically set only the minimum height of thisJComponent
.
This callsJComponent.setMinimumSize(Dimension)
on the underlying component for you.- Parameters:
height
- The minimum height which should be set for the underlying component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withMaxSize
Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
UsewithMaxSize(Size)
instead.Set the maximumDimension
of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component.- Parameters:
size
- The maximumDimension
of the component.- Returns:
- This very builder to allow for method chaining.
-
withMaxSize
Set the maximumSize
of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component.- Parameters:
size
- The maximumSize
of the component.- Returns:
- This very builder to allow for method chaining.
-
withMaxSize
Bind to aVal
object to dynamically set the maximumSize
of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component.- Parameters:
size
- The maximumSize
of the component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withMaxSize
Set the maximum width and height (Dimension
) of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component.- Parameters:
width
- The maximum width of the component.height
- The maximum height of the component.- Returns:
- This very builder to allow for method chaining.
-
withMaxSize
Bind to aVal
object to dynamically set the maximum size of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component.- Parameters:
width
- The maximum width of the component.height
- The maximum height of the component.- Returns:
- This very builder to allow for method chaining.
-
withMaxWidth
Use this to only set the maximum width of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component for you.- Parameters:
width
- The maximum width which should be set for the underlying component.- Returns:
- This very builder to allow for method chaining.
-
withMaxWidth
Use this to dynamically set only the maximum width of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component for you.- Parameters:
width
- The maximum width which should be set for the underlying component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withMaxHeight
Use this to only set the maximum height of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component for you.- Parameters:
height
- The maximum height which should be set for the underlying component.- Returns:
- This very builder to allow for method chaining.
-
withMaxHeight
Use this to dynamically set only the maximum height of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component for you.- Parameters:
height
- The maximum height which should be set for the underlying component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withPrefSize
Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
Please usewithPrefSize(Size)
instead.Set the preferredDimension
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
size
- The preferredDimension
of the component.- Returns:
- This very builder to allow for method chaining.
-
withPrefSize
Set the preferredSize
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
size
- The preferredSize
of the component.- Returns:
- This very builder to allow for method chaining.
-
withPrefSize
Bind to aVal
object to dynamically set the preferredSize
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
size
- A property holding the preferredSize
of the component.- Returns:
- This very builder to allow for method chaining.
-
withPrefSize
Set the preferred width and height (Dimension
) of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
width
- The preferred width of the component.height
- The preferred height of the component.- Returns:
- This very builder to allow for method chaining.
-
withPrefSize
Bind to aVal
object to dynamically set the preferredDimension
of thisJComponent
, which consists of a width and a height used as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
width
- The preferred width of the component.height
- The preferred height of the component.- Returns:
- This very builder to allow for method chaining.
-
withPrefWidth
Use this to only set the preferred width of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component for you.- Parameters:
width
- The preferred width which should be set for the underlying component.- Returns:
- This very builder to allow for method chaining.
-
_setPrefWidth
-
withPrefWidth
Use this to dynamically set only the preferred width of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component for you.- Parameters:
width
- The preferred width which should be set for the underlying component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withPrefHeight
Use this to only set the preferred height of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component for you.- Parameters:
height
- The preferred height which should be set for the underlying component.- Returns:
- This very builder to allow for method chaining.
-
withPrefHeight
Use this to dynamically set only the preferred height of thisJComponent
, which serves as a suggestion to theLayoutManager
of the parent container.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component for you.- Parameters:
height
- The preferred height which should be set for the underlying component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withSize
Deprecated.Due to the inherent pitfalls that come along with theDimension
being mutable!
Please usewithSize(Size)
instead.Set the currentDimension
)/size (width and height) of thisJComponent
.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
size
- The currentDimension
of the component.- Returns:
- This very builder to allow for method chaining.
-
withSize
Sets the currentSize
) (width and height) of thisJComponent
.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the size of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefSize(Size)
method instead.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
size
- The currentSize
of the component.- Returns:
- This very builder to allow for method chaining.
-
withSize
Bind to aVal
object to dynamically set the currentDimension
of thisJComponent
using aSize
object.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the size of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefSize(Val)
method instead.
TheSize
is automatically translated to a call toComponent.setSize(Dimension)
on the underlying component.- Parameters:
size
- The currentSize
of the component wrapped by aVal
property.- Returns:
- This very builder to allow for method chaining.
-
withSize
Allows you to directly set the width and height of the current component directly instead of through the layout manager.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the size of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefSize(int, int)
method instead.
Also note that this method translates to invokingComponent.setSize(Dimension)
on the underlying component.- Parameters:
width
- The width of the component.height
- The height of the component.- Returns:
- This very builder to allow for method chaining.
-
withWidth
Set the current width of thisJComponent
.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the set width of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefWidth(int)
method instead.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
width
- The current width of the component.- Returns:
- This very builder to allow for method chaining.
-
withWidth
Bind to aVal
object to dynamically set the current width of thisJComponent
.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the width of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefWidth(Val)
method instead.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
width
- The current width of the component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withHeight
Set the current height of thisJComponent
.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the height of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefHeight(int)
method instead.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
height
- The current height of the component.- Returns:
- This very builder to allow for method chaining.
-
withHeight
Bind to aVal
object to dynamically set the current height of thisJComponent
.
Note however that calling this method, may not necessarily have a visual effect on the component, as the layout manager may override the height of the component.
So in case of the component being part of a layout (which is the case most of the time), you may want to use thewithPrefHeight(Val)
method instead.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
height
- The current height of the component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withSizeExactly
Allows you to define a common width and height for the minimum, maximum, and preferred size of this component. This is a convenience method, which is equivalent to:
This method call translates to calling.withMinSize(width, height) .withMaxSize(width, height) .withPrefSize(width, height)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
width
- The min-, max- and preferred with of the component.height
- The min-, max- and preferred height of the component.- Returns:
- A declarative builder instance to allow for further method chaining.
-
withSizeExactly
Allows you to define a common width and height for the minimum, maximum, and preferred size of this component in the form of the suppliedSize
object. This is in essence a convenience method equivalent to:
Underneath, this method call translates to calling.withMinSize(size) .withMaxSize(size) .withPrefSize(size)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
size
- The min-, max- and preferredSize
of the component.- Returns:
- A declarative builder instance to allow for further method chaining.
-
withSizeExactly
Bind to aSize
object to dynamically update the common width and height for the minimum, maximum, and preferred size of this component. This is in essence a convenience method, which is equivalent to calling:
This method translates to calling.withMinSize(width, height) .withMaxSize(width, height) .withPrefSize(width, height)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
size
- A property wrapping the min-, max- and preferredSize
of the component. When the property item changes, the size of the component will be updated accordingly.- Returns:
- A declarative builder instance to allow for further method chaining.
-
withSizeExactly
Allows you to bind to twoVal
properties to dynamically update the common width and height for the minimum, maximum, and preferred size of this component. This is in essence a convenience method, which is equivalent to:
This method will translate the property updates to calling.withMinSize(width, height) .withMaxSize(width, height) .withPrefSize(width, height)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
width
- The min-, max- and preferred width of the component in the form of an integer property. When the property item changes, the width of the component will be updated accordingly.height
- The min-, max- and preferred height of the component in the form of an integer property. When the property item changes, the height of the component will be updated accordingly.- Returns:
- A declarative builder instance to allow for further method chaining.
- Throws:
NullPointerException
- If any of the provided properties isnull
.
-
withWidthExactly
Use this to set the min-, max- and preferred width of thisJComponent
to the same value.
This is a convenience method, which is equivalent to calling:
An invocation to this method translates to.withMinWidth(width) .withMaxWidth(width) .withPrefWidth(width)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
width
- The min-, max- and preferred width of the component.- Returns:
- A declarative builder instance to allow for further method chaining.
-
withWidthExactly
Use this to bind to aVal
property to dynamically update the min-, max- and preferred width of thisJComponent
to the same value.
So whenever the item of the property changes, all these widths will be updated automatically for you. This is a convenience method, which is equivalent to callingwithMinWidth(Val)
,withMaxWidth(Val)
andwithPrefWidth(Val)
on the underlying component.
Eventually, all of this ultimately translates to.withMinWidth(width) .withMaxWidth(width) .withPrefWidth(width)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
width
- The min-, max- and preferred width of the component wrapped by aVal
. When the property item changes, the width of the component will be updated accordingly.- Returns:
- A declarative builder instance to allow for further method chaining.
-
withHeightExactly
Use this to set the min-, max- and preferred height of thisJComponent
to the same value.
This is a convenience method, which is equivalent to calling:
An invocation to this method translates to.withMinHeight(height) .withMaxHeight(height) .withPrefHeight(height)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
height
- The min-, max- and preferred height of the component.- Returns:
- A declarative builder instance to allow for further method chaining.
-
withHeightExactly
Use this to bind to aVal
property to dynamically update the min-, max- and preferred height of thisJComponent
to the same value.
So whenever the item of the property changes, all these heights will be updated automatically for you. This is a convenience method, which is equivalent to callingwithMinHeight(Val)
,withMaxHeight(Val)
andwithPrefHeight(Val)
on the underlying component.
Eventually, all of this ultimately translates to.withMinHeight(height) .withMaxHeight(height) .withPrefHeight(height)
JComponent.setMinimumSize(Dimension)
,JComponent.setMaximumSize(Dimension)
, andJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
height
- The min-, max- and preferred height of the component wrapped by aVal
. When the property item changes, the height of the component will be updated accordingly.- Returns:
- A declarative builder instance to allow for further method chaining.
-
onMouseClick
Calls the provided action event handler when the mouse gets pressed and then released. This delegates to aMouseListener
based mouse click event listener registered in the UI component.
Note that a click is defined as the combination of the mouse being pressed and then released on the same position as it was pressed. If the mouse moves between the press and the release events, then the event is considered a drag event instead of a mouse click! (seeonMouseDrag(Action)
)- Parameters:
onClick
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseRelease
Use this to register and catch genericMouseListener
based mouse release events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- Parameters:
onRelease
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMousePress
Use this to register and catch genericMouseListener
based mouse press events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- Parameters:
onPress
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseEnter
Use this to register and catch mouse enter events on theUI.ComponentArea.BODY
of this UI component,
which consists of the full component boundaries except for the surrounding margins and corner rounding areas.
If you want to catch mouse enter events on a different area of the component, use
onMouseEnter(UI.ComponentArea, Action)
instead. Internally, this method adds the suppliedAction
lambda to a custom event dispatcher which ensures that the mouse enter event is only triggered when the mouse enters the boundaries of the specified area, irrespective of the existence of child components.- Parameters:
onEnter
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseEnter
public final I onMouseEnter(UI.ComponentArea area, sprouts.Action<ComponentMouseEventDelegate<C>> onEnter) Use this to register and catch mouse enter events on a specific area of this UI component, defined by the first argument, aUI.ComponentArea
enum value, and the second argument, a lambda instance which will be invoked when the mouse enters the specified area. Internally, the providedAction
lambda is handled by a custom event dispatcher which ensures that the mouse enter event is only triggered when the mouse enters the boundaries of the specified area, irrespective of the existence of child components.
Note that this mouse enter event is different from the native Swing mouse enter event, which also considers child components with mouse listeners as enter/exit boundaries.
If you want to rely on this the Swing behavior, useonMouseEnterGreedy(Action)
instead.
We do however recommended to rely on this method, to avoid bugs due to the unexpected side effect of enter events being fired at the boundary to child components.- Parameters:
area
- The specific area of the component where the mouse enter event should be caught.onEnter
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseEnterGreedy
Use this to register and catch simpleMouseListener
based mouse enter events on this UI component. This method adds the suppliedAction
lambda in aMouseListener
instance to the component.
This method is greedy in the sense that in case of the parent of this component also having a mouse listener, then a mouse cursor transition on top of this component will be considered an exit from the parent component and an enter into this component.
If you want to catch mouse enter events strictly in terms of the cursor being inside the component boundaries, or one of its areas, useonMouseEnter(Action)
, oronMouseEnter(UI.ComponentArea, Action)
instead.
To avoid bugs due to the unexpected side effect of enter events being fired at the surface boundaries to child components, we recommend to use
onMouseEnter(Action)
instead of this method!
Also note that this method is different fromonMouseEnter(Action)
, in that it reports enter events at the boundaries ofUI.ComponentArea.ALL
instead ofUI.ComponentArea.BODY
.- Parameters:
onEnter
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseExit
Use this to register and catch mouse exit events on theUI.ComponentArea.BODY
of this UI component,
which consists of the full component boundaries except for the surrounding margins and corner rounding areas.
If you want to catch mouse exit events on a different area than the body of the component, use
onMouseExit(UI.ComponentArea, Action)
instead. Internally, this method adds the suppliedAction
lambda to a custom event dispatcher which ensures that the mouse exit event is only triggered when the mouse exits the boundaries of the specified area, irrespective of the existence of child components.
Note that this mouse enter event is different from the native Swing mouse enter event, which also considers child components with mouse listeners as enter/exit event boundaries.
If you want to rely on this the Swing behavior, useonMouseExitGreedy(Action)
instead.
We do however recommended to rely on this method, to avoid bugs due to the unexpected side effect of exit events being fired at the boundary to child components.- Parameters:
onExit
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseExit
public final I onMouseExit(UI.ComponentArea area, sprouts.Action<ComponentMouseEventDelegate<C>> onExit) Use this to register and catch mouse exit events on a specific area of this UI component, by supplying aUI.ComponentArea
enum value to define the area, and aAction
lambda which will be invoked when the mouse exits the specified area, so that you can react to the event accordingly.
Internally, the provided
Action
lambda is handled by a custom event dispatcher which ensures that the mouse exit event is only triggered when the mouse exits the boundaries of the specified area, irrespective of the existence of child components.
Note that this mouse exit event is different from the native Swing mouse exit event, which also considers child components with mouse listeners as enter/exit boundaries. If you want to rely on the native Swing behavior, useonMouseExitGreedy(Action)
instead of this method.- Parameters:
area
- The specific area of the component where the mouse exit event should be caught.onExit
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseExitGreedy
Use this to register and catch simpleMouseListener
based mouse exit events on this UI component. This method adds the suppliedAction
lambda in aMouseListener
instance to the component.
The method is considered greedy in the sense that in case of the parent of this component also having a mouse listener, then a mouse cursor transition over to be on top of this component will be considered an exit from the parent components and an enter into this component.
If you want to catch mouse exit events strictly in terms of the cursor being inside the component boundaries, or one of its areas, useonMouseExit(Action)
, oronMouseExit(UI.ComponentArea, Action)
instead.
To avoid bugs due to the unexpected side effect of exit events being fired at the surface boundaries to child components, we recommend to use
onMouseExit(Action)
instead of this method!
Also note that this method is different fromonMouseExit(Action)
, in that it reports exit events at the boundaries ofUI.ComponentArea.ALL
instead ofUI.ComponentArea.BODY
.- Parameters:
onExit
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseDrag
Use this to register and catch genericMouseListener
based mouse drag events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.
TheComponentDragEventDelegate
received by theAction
lambda exposes both component and drag event context information, including a list of all theMouseEvent
s involved in one continuous dragging motion (seeComponentDragEventDelegate.dragEvents()
for more information).- Parameters:
onDrag
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseMove
Use this to register and catch genericMouseListener
based mouse move events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- Parameters:
onMove
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseWheelMove
Use this to register and catch genericMouseListener
based mouse wheel events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- Parameters:
onWheel
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseWheelUp
Use this to register and catch mouse wheel up movement events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- Parameters:
onWheelUp
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMouseWheelDown
Use this to register and catch mouse wheel down movement events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- Parameters:
onWheelDown
- The lambda instance which will be passed to the button component asMouseListener
.- Returns:
- This very instance, which enables builder-style method chaining.
-
onResize
The provided lambda will be invoked when the component's size changes. This will internally translate to aComponentListener
implementation. Passing null to this method will cause an exception to be thrown.- Parameters:
onResize
- The resize action which will be called when the underlying component changes size.- Returns:
- This very instance, which enables builder-style method chaining.
-
onMoved
The provided lambda will be invoked when the component was moved. This will internally translate to aComponentListener
implementation.- Parameters:
onMoved
- The action lambda which will be executed once the component was moved / its position canged.- Returns:
- This very instance, which enables builder-style method chaining.
-
onShown
Adds the suppliedAction
wrapped in aAncestorListener
to the component, to receive calls when the wrapped component becomes visible on the screen.
Note that this does not correlate 1:1 with the
Component.isVisible()
flag, because a component may also be invisible when it is not part of the component hierarchy with a visible root component (window) or one of its ancestors (parent components) is not visible.- Parameters:
onShown
- TheAction
which gets invoked when the component has been made visible- Returns:
- This very instance, which enables builder-style method chaining.
-
onHidden
Adds the suppliedAction
wrapped in aAncestorListener
to the component, to receive calls when the wrapped component becomes invisible on the users screen.
Note that this does not correlate 1:1 with the
Component.isVisible()
flag, because a component may also be invisible when it is not part of the component hierarchy with a visible root component (window) or one of its ancestors (parent components) is not visible.- Parameters:
onHidden
- TheAction
which gets invoked when the component has been made invisible.- Returns:
- This very instance, which enables builder-style method chaining.
-
onFocusGain
Adds the suppliedAction
wrapped in aFocusListener
to the component, to receive those focus events where the wrapped component gains input focus.- Parameters:
onFocus
- TheAction
which should be executed once the input focus was gained on the wrapped component.- Returns:
- This very instance, which enables builder-style method chaining.
-
onFocusLoss
Adds the suppliedAction
wrapped in a focus listener to receive those focus events where the wrapped component loses input focus.- Parameters:
onFocus
- TheAction
which should be executed once the input focus was lost on the wrapped component.- Returns:
- This very instance, which enables builder-style method chaining.
-
onKeyPress
Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives keyboard input.- Parameters:
onKeyPressed
- TheAction
which will be executed once the wrapped component received a key press.- Returns:
- This very instance, which enables builder-style method chaining.
-
onPressed
public final I onPressed(Keyboard.Key key, sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyPressed) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the providedKeyboard.Key
.- Parameters:
key
- TheKeyboard.Key
which should be matched to the key event.onKeyPressed
- TheAction
which will be executed once the wrapped component received the targeted key press.- Returns:
- This very instance, which enables builder-style method chaining.
-
onKeyRelease
Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives keyboard input.- Parameters:
onKeyReleased
- TheAction
which will be executed once the wrapped component received a key release.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
onRelease
public final I onRelease(Keyboard.Key key, sprouts.Action<ComponentDelegate<C, KeyEvent>> onKeyReleased) Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the built component receives a particular keyboard input matching the providedKeyboard.Key
.- Parameters:
key
- TheKeyboard.Key
which should be matched to the key event.onKeyReleased
- TheAction
which will be executed once the wrapped component received the targeted key release.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
onKeyTyped
Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives keyboard input.- Parameters:
onKeyTyped
- TheAction
which will be executed once the wrapped component received a key typed.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
onTyped
Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the providedKeyboard.Key
.- Parameters:
key
- TheKeyboard.Key
which should be matched to the key event.onKeyTyped
- TheAction
which will be executed once the wrapped component received the targeted key typed.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
onTyped
Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the provided character.
This method is a logical extension of theonTyped(Keyboard.Key, Action)
method, with the difference that it listens for any character instead of a specific key code. This also works with special characters which are typed using the combination of multiple keys (e.g. shift + number keys).- Parameters:
character
- The character to listen for.onKeyTyped
- The action to execute when the character is typed.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
onCharTyped
Adds the suppliedAction
wrapped in aKeyListener
to the component, to receive key events triggered when the wrapped component receives a particular keyboard input matching the provided character.
This method is a logical extension of theonTyped(Keyboard.Key, Action)
method, with the difference that it listens for any character instead of a specific key code. This also works with special characters which are typed using the combination of multiple keys (e.g. shift + number keys).- Parameters:
onKeyTyped
- The action to execute when the character is typed.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
withDragAway
Exposes a functionalConfigurator
API for turning the component into a drag source site with the given configuration. This method is a convenience method which internally creates and configures an AWT nativeDragSource
instance for the component.
Here an example:
The example above creates a draggable label which will be dragged with an opacity of 0.25 and carries the payload "IT WORKS" when dragged. The drag move event handler is attached to the drag source site and will be called when the label is dragged.UI.label("Drag me!") .withDragAway( conf -> conf .enabled(true) .opacity(0.25) .payload("IT WORKS") .onDragMove( it -> {...}) )
If you want to create a drop site instead of a drag source site, use
withDropSite(Configurator)
.- Parameters:
configurator
- TheConfigurator
which allows you to configure the drag source site by receiving aDragAwayComponentConf
instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
withDropSite
Exposes a functionalConfigurator
API for turning the component into a drag drop receiver site with the given configuration. This method is a convenience method which internally creates and configures an AWT nativeDropTarget
instance for the component.
Here an example:
The example above creates a drop site label which will animate an expanding circle when a drag is over it and another circle when a drop is performed on it. The drag over event handler is attached to the drop site and will be called when the label is dragged over it.UI.label("Drop here!") .withDropSite( conf -> conf .onDragOver( it -> { it.animateFor(1, TimeUnit.SECONDS, status -> { double r = 30 * status.fadeIn() * it.getScale(); double x = it.getEvent().getLocation().x - r / 2.0; double y = it.getEvent().getLocation().y - r / 2.0; it.paint(status, g -> { g.setColor(new Color(0f, 1f, 1f, (float) status.fadeOut())); g.fillOval((int) x, (int) y, (int) r, (int) r); }); }); }) .onDrop(it -> { it.animateFor(2, TimeUnit.SECONDS, status -> { double r = 480 * status.fadeIn() * it.getScale(); double x = it.getEvent().getLocation().x - r / 2.0; double y = it.getEvent().getLocation().y - r / 2.0; it.paint(status, g -> { g.setColor(UI.color(0.5+status.fadeOut()/2, status.fadeOut(), status.fadeIn(), status.fadeOut())); g.fillOval((int) x, (int) y, (int) r, (int) r); }); }); }) )
If you want to create a drag source site instead of a drop site, use
withDragAway(Configurator)
.- Parameters:
configurator
- TheConfigurator
which allows you to configure the drop site by receiving aDragDropComponentConf
instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
onView
public final <E extends sprouts.Observable> I onView(E observableEvent, sprouts.Action<ComponentDelegate<C, E>> action) Allows you to cause an effect inside your UI when an observable event is fired. The providedAction
event handler will be called on the UI thread when theObservable
event is fired, irrespective of what thread theObservable
event is fired on. However, it is expected that theObservable
event is fired on the application thread and the concrete implementation of theObservable
is intended to be part of your view model.
Here an example:UI.label("I have a color animation!") .on(viewModel.someEvent(), it -> it.animateFor(3, TimeUnit.SECONDS, status -> { double r = status.progress(); double g = 1 - status.progress(); double b = status.pulse(); it.setBackgroundColor(r, g, b); }) )
- Type Parameters:
E
- The type of theObservable
event.- Parameters:
observableEvent
- TheObservable
event to which theAction
should be attached and called on the UI thread when the event is fired in the view model.action
- TheAction
which is invoked by the UI thread after theObservable
event was fired by the business logic of the view model.- Returns:
- This very instance, which enables builder-style method chaining.
-
on
public final <E extends sprouts.Observable> I on(E observableEvent, sprouts.Action<ComponentDelegate<C, E>> action) Use this to attach a componentAction
event handler to a functionally suppliedObservable
event in order to implement a custom user event system. The suppliedAction
is executed on the application thread when theObservable
event is fired and irrespective of the thread thatObservable
fired the event.
TheAction
is expected to perform an effect on the view model or the application state, but not on the UI directly.
(seeonView(Observable, Action)
if you want your view model to affect the UI through an observable event)
Consider the following example:
In this example we use an imaginaryUI.label("") .on(CustomEventSystem.touchGesture(), it -> ..some App update.. )
CustomEventSystem
to register a touch gesture event handler which will be called on the application thread when the touch gesture event is fired. Although neither Swing nor SwingTree have a touch gesture event system, this example illustrates how one could easily integrate a custom event system into SwingTree UIs.
Note that the providedObservable
event is NOT expected to be part of the view model, but rather part of a custom event system that captures user input or other input which is not directly related to the business logic of the view model.- Type Parameters:
E
- The type of theObservable
event.- Parameters:
observableEvent
- TheObservable
event to which theAction
should be attached.action
- TheAction
which is invoked by the application thread after theObservable
event was fired.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
on
public final <E extends sprouts.Observable> I on(Function<C, E> eventSource, sprouts.Action<ComponentDelegate<C, E>> action) This is a logical extension of theon(Observable, Action)
method. Use this to attach a componentAction
event handler to a functionally suppliedObservable
event. TheAction
will be called on the application thread when theObservable
event is fired, irrespective of the thread that fired theObservable
event. TheAction
is expected to perform an effect on the view model or the application state, but not on the UI directly.
(seeonView(Observable, Action)
if you want your view model to affect the UI through an observable event)
Consider the following example:
Which may also be written as:UI.label("") .on(c -> CustomEventSystem.touchGesture(c), it -> ..some App update.. )
In this example we use an imaginaryUI.label("") .on(CustomEventSystem::touchGesture, it -> ..some App update.. )
CustomEventSystem
to register a component specific touch gesture event handler which will be called on the application thread when the touch gesture event is fired. Although neither Swing nor SwingTree have a touch gesture event system, this example illustrates how one could easily integrate a custom event system into SwingTree UIs.
Note that theObservable
event supplied by the function is NOT expected to be part of the view model, but rather be part of a custom event system that captures user input or other input which is not directly related to the business logic of the view model.- Type Parameters:
E
- The type of theObservable
event.- Parameters:
eventSource
- TheObservable
event to which theAction
should be attached.action
- TheAction
which is invoked by the application thread after theObservable
event was fired.- Returns:
- This very instance, which enables builder-style method chaining.
- See Also:
-
doUpdates
Use this to register periodic update actions which should be called based on the provideddelay
!
The following example produces a label which will display the current date.UI.label("") .doUpdates( 100, it -> it.getComponent().setText(new Date().toString()) )
- Parameters:
delay
- The delay in milliseconds between calling the providedAction
.onUpdate
- TheAction
which should be called periodically.- Returns:
- This very instance, which enables builder-style method chaining.
-
_addComponentTo
protected void _addComponentTo(C thisComponent, JComponent addedComponent, @Nullable AddConstraint constraints) Description copied from class:UIForAnything
This builder class expects its implementations to be builder types for anything which can be built in a nested tree-like structure. Implementations of this abstract method ought to enable support for nested building.- Specified by:
_addComponentTo
in classUIForAnything<I,
C extends JComponent, JComponent> - Parameters:
thisComponent
- The component which is wrapped by this builder.addedComponent
- A component instance which ought to be added to the wrapped component type.constraints
- The layout constraint which ought to be used to add the component to the wrapped component type.
-
add
Use this to nest builder nodes into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance. The first argument is expected to contain layout information for the layout manager of the wrappedJComponent
, through theContainer.add(Component, Object)
method. By default, theMigLayout
is used.- Type Parameters:
T
- The type of theJComponent
which is wrapped by the provided builder.- Parameters:
attr
- The additional mig-layout information which should be passed to the UI tree.builder
- A builder for anotherJComponent
instance which ought to be added to the wrapped component type.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
Use this to nest builder nodes into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance. The first argument will be passed to the layout manager of the wrappedJComponent
, through theContainer.add(Component, Object)
method. By default, theMigLayout
is used.- Type Parameters:
T
- The type of theJComponent
which is wrapped by the provided builder.- Parameters:
attr
- The mig-layout attribute.builder
- A builder for anotherJComponent
instance which ought to be added to the wrapped component type.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
Use this to nest builder types into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance. The first argument represents layout attributes/constraints which will be passed to theLayoutManager
of the underlyingJComponent
. through theContainer.add(Component, Object)
method.
This may look like this:
Note that the first argument, "wrap" and "grow" in this case, are used as layout constraints for all theUI.panel() .add("wrap", UI.label("A"), UI.label("B")) .add("grow", UI.label("C"), UI.label("D"))
JComponent
s which are added in the subsequent arguments of a single call to this method.- Type Parameters:
B
- The builder type parameter, a subtype ofUIForAnySwing
.- Parameters:
attr
- The additional mig-layout information which should be passed to the UI tree.builders
- An array of builders for a corresponding number ofJComponent
type which ought to be added to the wrapped component type of this builder.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
Use this to nest builder types into this builder to effectively plug the wrappedJComponent
s into theJComponent
type wrapped by this builder instance. The first argument will be passed to theLayoutManager
of the underlyingJComponent
to serve as layout constraints through theContainer.add(Component, Object)
method.- Type Parameters:
B
- The builder type parameter, a subtype ofUIForAnySwing
.- Parameters:
attr
- The first mig-layout information which should be passed to the UI tree.builders
- An array of builders for a corresponding number ofJComponent
type which ought to be added to the wrapped component type of this builder.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
@SafeVarargs public final <B extends UIForAnySwing<?,?>> I add(net.miginfocom.layout.CC attr, B... builders) Use this to nest builder types into this builder to effectively plug theJComponent
s wrapped by the provided builders into theJComponent
type wrapped by this builder instance. The first argument represents placement constraints for the provided components which will be passed to theMigLayout
of the underlyingJComponent
through theContainer.add(Component, Object)
method.- Type Parameters:
B
- The builder type parameter, a subtype ofUIForAnySwing
.- Parameters:
attr
- The additional mig-layout information which should be passed to the UI tree.builders
- An array of builders for a corresponding number ofJComponent
type which ought to be added to the wrapped component type of this builder.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
Use this to nestJComponent
types into this builder to effectively plug the providedJComponent
s into theJComponent
type wrapped by this builder instance. The first argument represents layout attributes/constraints which will be applied to the subsequently providedJComponent
types.
This may look like this:
Note that the first argument, "wrap" and "grow" in this case, are used as layout constraints for all theUI.panel() .add("wrap", new JLabel("A"), new JLabel("B")) .add("grow", new JLabel("C"), new JLabel("D"))
JComponent
s which are added in the subsequent arguments of a single call to this method.- Type Parameters:
E
- The type of theJComponent
which is wrapped by the provided builder.- Parameters:
attr
- The additional layout information which should be passed to the UI tree.components
- AJComponent
s array which ought to be added to the wrapped component type.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
Use this to nestJComponent
types into this builder to effectively plug the providedJComponent
s into theJComponent
type wrapped by this builder instance. The first 2 arguments will be joined by a comma and passed to theLayoutManager
of the underlyingJComponent
to serve as layout constraints.- Type Parameters:
E
- The type of theJComponent
which is wrapped by the provided builder.- Parameters:
attr
- The first layout information which should be passed to the UI tree.components
- AJComponent
s array which ought to be added to the wrapped component type.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
This allows you to dynamically generate a view for the item of a property (usually a property holding a sub-view model) and automatically regenerate the view when the property changes. TheViewSupplier
lambda passed to this method will receive the value of the property and is then expected to return aJComponent
instance which will be added to the wrappedJComponent
type of this builder.- Type Parameters:
M
- The type of the value held by theVal
property.- Parameters:
model
- AVal
property holding null or any other type of value, preferably a view model instance.viewSupplier
- AViewSupplier
instance which will be used to generate the view for the value held by the property.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
This allows you to dynamically generate a view for the item of a property (usually a property holding a sub-view model) and automatically regenerate the view when the property changes. TheViewSupplier
lambda passed to this method will receive the value of the property and is then expected to return aJComponent
instance which will be added to the wrappedJComponent
type of this builder.- Type Parameters:
M
- The type of the value held by theVal
property.- Parameters:
attr
- The layout information which should be used as layout constraints for the generated view.model
- AVal
property holding null or any other type of value, preferably a view model instance.viewSupplier
- AViewSupplier
instance which will be used to generate the view for the value held by the property.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
This allows you to dynamically generate a view for the item of a property (usually a property holding a sub-view model) and automatically regenerate the view when the property changes. TheViewSupplier
lambda passed to this method will receive the value of the property and is then expected to return aJComponent
instance which will be added to the wrappedJComponent
type of this builder.- Type Parameters:
M
- The type of the value held by theVal
property.- Parameters:
attr
- The layout information which should be used as layout constraints for the generated view.model
- AVal
property holding null or any other type of value, preferably a view model instance.viewSupplier
- AViewSupplier
instance which will be used to generate the view for the value held by the property.- Returns:
- This very instance, which enables builder-style method chaining.
-
addAll
This allows you to dynamically generate views for the items in aVals
property list and automatically regenerate the view when any of the items change. The type of item can be anything, but it is usually a view model instance. TheViewSupplier
lambda passed to this method will receive the value of the property and is then expected to return aJComponent
instance which will be added to the wrappedJComponent
type of this builder.
Due to the usage of the mutable theVals
property list, this method assumes your view models to be based on place oriented programming practices. Although SwingTree offers API for this style of programming, we strongly recommend using value objects for your view models andTuple
s instead ofVals
lists.
SeeaddAll(Val, ViewSupplier)
as the recommended alternative to this method.- Type Parameters:
M
- The type of the items in theVals
list.- Parameters:
models
- AVals
list of items of any type but preferably view model instances.viewSupplier
- AViewSupplier
instance which will be used to generate the view for each item in the list. The views will be added to the component wrapped by this builder instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
addAll
This allows you to dynamically generate views for the items in aVals
property list and automatically regenerate the view when any of the items change. The type of item can be anything, but it is usually a view model instance. TheViewSupplier
lambda passed to this method will receive the value of the property and is then expected to return aJComponent
instance which will be added to the wrappedJComponent
type of this builder.
Due to the usage of the mutable theVals
property list, this method assumes your view models to be based on place oriented programming practices. Although SwingTree offers API for this style of programming, we strongly recommend using value objects for your view models andTuple
s instead ofVals
lists.
SeeaddAll(String, Val, ViewSupplier)
as the recommended alternative to this method.- Type Parameters:
M
- The type of the items in theVals
list.- Parameters:
attr
- The layout information which should be used as layout constraints for the generated views.models
- AVals
list of items of any type but preferably view model instances.viewSupplier
- AViewSupplier
instance which will be used to generate the view for each item in the list. The views will be added to the component wrapped by this builder instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
addAll
This allows you to dynamically generate views for the items in aVals
property list and automatically regenerate the view when any of the items change. The type of item can be anything, but it is usually a view model instance. TheViewSupplier
lambda passed to this method will receive the value of the property and is then expected to return aJComponent
instance which will be added to the wrappedJComponent
type of this builder.
Due to the usage of the mutable theVals
property list, this method assumes your view models to be based on place oriented programming practices. Although SwingTree offers API for this style of programming, we strongly recommend using value objects for your view models andTuple
s instead ofVals
lists.
SeeaddAll(AddConstraint, Val, ViewSupplier)
as the recommended alternative to this method.- Type Parameters:
M
- The type of the items in theVals
list.- Parameters:
attr
- The layout information which should be used as layout constraints for the generated views.models
- AVals
list of items of any type but preferably view model instances.viewSupplier
- AViewSupplier
instance which will be used to generate the view for each item in the list. The views will be added to the component wrapped by this builder instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
addAll
Dynamically generate views for the items in aTuple
of items, and automatically regenerate the view when any of the items in the tuple change. The type of item can be anything, but it is usually value based view models. TheViewSupplier
lambda passed to this method will be invoked with each item in the tuple and is expected to return aJComponent
instance which will either be added to this UI component or replace an existing view.- Type Parameters:
M
- The type of the items in theTuple
, which is the type of the view model.- Parameters:
models
- A property of aTuple
of items of any type but preferably view model instances.viewSupplier
- AViewSupplier
instance which will be used to generate the view for each item in the tuple.- Returns:
- This very instance, which enables builder-style method chaining.
-
addAll
public final <M> I addAll(String attr, sprouts.Val<sprouts.Tuple<M>> models, ViewSupplier<M> viewSupplier) -
addAll
public final <M> I addAll(AddConstraint attr, sprouts.Val<sprouts.Tuple<M>> viewables, ViewSupplier<M> viewSupplier) -
_addViewableProps
protected <M> void _addViewableProps(sprouts.Vals<M> models, @Nullable AddConstraint attr, swingtree.ModelToViewConverter<M> viewSupplier, C thisComponent) -
_addViewableProps
protected <M> void _addViewableProps(sprouts.Val<sprouts.Tuple<M>> models, @Nullable AddConstraint attr, swingtree.ModelToViewConverter<M> viewSupplier, C thisComponent)
-
withBackground(Color)
instead, by passing it theUI.Color.TRANSPARENT
constant.Alternatively, you may use the
UIForAnything.peek(Peeker)
method to peek into the builder's component and set the flag directly.