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
-
Method Summary
Modifier and TypeMethodDescriptionprotected final <B extends swingtree.UIForAnything<?,
?, JComponent>>
void_addBuildersTo
(C thisComponent, B... builders) protected final void
_addBuilderTo
(C thisComponent, swingtree.UIForAnything<?, ?, ?> builder, @Nullable Object conf) protected final void
_addComponentsTo
(C thisComponent, JComponent... componentsToBeAdded) protected void
_addComponentTo
(C thisComponent, JComponent addedComponent, @Nullable Object 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.Vals<M> models, @Nullable String attr, ViewSupplier<M> viewSupplier, C thisComponent) protected final void
This method is used to dispose of the state of the builder, which means that the builder state disposes of its reference to either the wrapped component or the wrapped component or the composite of component factories which are used to build the wrapped component eagerly each time the wrapped component is accessed.protected final boolean
_isUndefinedColor
(Color color) protected final boolean
_isUndefinedFont
(Font font) protected abstract swingtree.UIForAnything<I,
C, JComponent> _newBuilderWithState
(swingtree.BuilderState<C> newState) An internal wither method which creates a new builder instance with the providedBuilderState
stored inside it.protected final <T> void
_onShow
(sprouts.Val<T> val, C thisComponent, BiConsumer<C, T> displayAction) Use this to register a state change listener for the provided property which will be executed by the UI thread (seeEventProcessor
).protected final <T> void
_onShow
(sprouts.Vals<T> vals, C c, BiConsumer<C, sprouts.ValsDelegate<T>> displayAction) Use this to register a state change listener for the provided property list which will be executed by the UI thread (seeEventProcessor
).protected final void
A convenient delegate to theEventProcessor.registerAppEvent(Runnable)
method, which allows you to execute an action on the current application thread.protected final <T> void
A convenient delegate to theEventProcessor.registerAppEvent(Runnable)
method, which allows you to execute an action on the current application thread.protected final void
A convenient shortcut to theEventProcessor.registerUIEvent(Runnable)
method to the currentEventProcessor
attached to the currentBuilderState
.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) protected abstract swingtree.BuilderState<C>
_state()
Returns the state of the builder, which is a container for the wrapped component as well as it's type and currentEventProcessor
.protected final I
_this()
Exposes the this-pointer of the builder instance cast to theI
type parameter of the builder class.protected final swingtree.UIForAnything<I,
C, JComponent> Creates a new builder with the provided component mutation applied to the wrapped component.protected final <T> swingtree.UIForAnything<I,
C, JComponent> _withOnShow
(sprouts.Val<T> val, BiConsumer<C, T> displayAction) protected final <T> swingtree.UIForAnything<I,
C, JComponent> _withOnShow
(sprouts.Vals<T> vals, BiConsumer<C, sprouts.ValsDelegate<T>> displayAction) final <B extends swingtree.UIForAnything<?,
?, JComponent>>
Iadd
(B... builders) This method provides the same functionality as the other "add" methods.final I
add
(JComponent... components) This builder class expects its implementations to be builder types for anything which can be built in a nested tree-like structure.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> viewable, 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 <M> I
add
(String attr, sprouts.Vals<M> viewables, 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 <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 I
add
(List<JComponent> components) This builder class expects its implementations to be builder types for anything which can be built in a nested tree-like structure.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> viewable, 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 <M> I
add
(sprouts.Vals<M> viewables, 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 <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> viewable, 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 <M> I
add
(AddConstraint attr, sprouts.Vals<M> viewables, 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 <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 <T extends JComponent>
Iadd
(UIForAnySwing<?, T> builder) Uses the supplied builder to build its component and then add it to the component that is being built by this builder instance.final I
Use this to continue building UI inside a provided lambda if you need to introduce some imperative code in between the building process.final I
Use this to only build a certain part of the UI if the provided boolean condition is true.final I
applyIfPresent
(Optional<Consumer<I>> building) Allows you to build declarative UI conditionally, meaning that the UI is only built if the providedOptional
value is present.final OptionalUI<C>
Deprecated.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.final boolean
final C
This method completes the building process for the wrappedJComponent
type by returning it.final C
Deprecated.Useget(Class)
instead.getType()
The type class of the component managed by this builder.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.final int
hashCode()
id
(E id) This method exposes a concise way to set an enum based identifier for the component wrapped by thisUI
! 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").final I
This method exposes a concise way to set an identifier for the component wrapped by thisUI
! 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").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.UsewithBackground(Color)
instead, by passing it theUI.Color.TRANSPARENT
constant.
Alternatively, you may use thepeek(Peeker)
method to peek into the builder's component and set the flag directly.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, ComponentEvent>> onHidden) Adds the suppliedAction
wrapped in aComponentListener
to the component, to receive those component events where the wrapped component becomes invisible.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 genericMouseListener
based mouse enter events on this UI component.final I
onMouseExit
(sprouts.Action<ComponentMouseEventDelegate<C>> onExit) Use this to register and catch genericMouseListener
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 wrapped 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, ComponentEvent>> onShown) Adds the suppliedAction
wrapped in aComponentListener
to the component, to receive those component events where the wrapped component becomes visible.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
Use this if you wish to access the component wrapped by this builder directly.final String
toString()
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 thepeek(Peeker)
method like so:final I
withBackground
(sprouts.Val<Color> bg) Use this to bind to aVal
containing a background color.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) Use this to dynamically attach a border to the wrapped 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
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
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
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
(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
(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) Set the maximumDimension
of thisJComponent
.final I
withMaxSize
(sprouts.Val<Dimension> size) final I
withMaxSize
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) 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) Set the minimumDimension
of thisJComponent
.final I
withMinSize
(sprouts.Val<Dimension> size) final I
withMinSize
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) 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
.final I
withPrefHeight
(sprouts.Val<Integer> height) Use this to dynamically set only the preferred height of thisJComponent
.final I
withPrefSize
(int width, int height) Set the preferred width and height (Dimension
) of thisJComponent
.final I
withPrefSize
(Dimension size) Set the preferredDimension
of thisJComponent
.final I
withPrefSize
(sprouts.Val<Dimension> size) final I
withPrefSize
(sprouts.Val<Integer> width, sprouts.Val<Integer> height) final I
withPrefWidth
(int width) Use this to only set the preferred width of thisJComponent
.final I
withPrefWidth
(sprouts.Val<Integer> width) Use this to dynamically set only the preferred width of thisJComponent
.final I
withProperty
(String key, String value) AddsString
key/value "client property" pairs to the wrapped component.final I
withRepaintOn
(sprouts.Observable event) This method exposes a concise way to bind aObservable
(usually a sprouts.Event to theComponent.repaint()
method of the component wrapped by thisUI
! This means that the component will be repainted whenever the event is fired.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) Set the current width and height of thisJComponent
.final I
Set the currentDimension
)/size (width and height) of thisJComponent
.final I
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
.
-
Constructor Details
-
UIForAnySwing
public UIForAnySwing()
-
-
Method Details
-
_isUndefinedFont
-
_isUndefinedColor
-
withRepaintOn
This method exposes a concise way to bind aObservable
(usually a sprouts.Event to theComponent.repaint()
method of the component wrapped by thisUI
! This means that the component will be repainted whenever the event is fired.- Parameters:
event
- The event to which the repaint method of the component will be bound.- Returns:
- The JComponent type which will be managed by this builder.
-
id
This method exposes a concise way to set an identifier for the component wrapped by thisUI
! 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 wrapped by thisUI
! 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 thepeek(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 thepeek(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
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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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 thepeek(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.
-
_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:
colorIfTrue
- The background color which should be set for the UI component.condition
- The condition property which determines whether the background color should be set or not.- 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:
color
- The background color property which should be set for the UI component.condition
- The condition property which determines whether the background color should be set or not.- 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 aAnimationState.progress()
of1.0
over the providedLifeTime
. And when the value of this property isfalse
, the style will transition to aAnimationState.progress()
of0.0
over the providedLifeTime
.transitionLifeTime
- TheLifeTime
of the transition animation. It defines for ow long theAnimationState.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 anAnimationState
and aComponentStyleDelegate
and returning an updated version with the desired style rules applied. TheAnimatedStyler
may apply the style properties according to theAnimationState
and itsAnimationState.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 anAnimationState
and aComponentStyleDelegate
and returning an updated version with the desired style rules applied. TheAnimatedStyler
may apply the style properties according to theAnimationState
and itsAnimationState.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 thepeek(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.
-
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:
fg
- The foreground color which should be set for the UI component.condition
- The condition property which determines whether the foreground color should be set or not.- 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:
color
- The foreground color property which should be set for the UI component.condition
- The condition property which determines whether the foreground color should be set or not.- 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
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
Bind to aVal
object to dynamically set the maximumDimension
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 minimumDimension
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
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
Bind to aVal
object to dynamically set the maximumDimension
of thisJComponent
.
This callsJComponent.setMaximumSize(Dimension)
on the underlying component.- Parameters:
size
- The maximumDimension
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 maximumDimension
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
Set the preferredDimension
of thisJComponent
.
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
Bind to aVal
object to dynamically set the preferredDimension
of thisJComponent
.
This callsJComponent.setPreferredSize(Dimension)
on the underlying component.- Parameters:
size
- The preferredDimension
of the component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withPrefSize
Set the preferred width and height (Dimension
) of thisJComponent
.
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
.
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
.
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
.
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
.
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
.
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
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
Bind to aVal
object to dynamically set the currentDimension
of thisJComponent
.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
size
- The currentDimension
of the component wrapped by aVal
.- Returns:
- This very builder to allow for method chaining.
-
withSize
Set the current width and height of thisJComponent
.
This callsComponent.setSize(Dimension)
on the underlying component.- Parameters:
width
- The current width of the component.height
- The current height of the component.- Returns:
- This very builder to allow for method chaining.
-
withWidth
Set the current width of thisJComponent
.
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
.
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
.
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
.
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.
-
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 genericMouseListener
based mouse enter events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- 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 genericMouseListener
based mouse exit events on this UI component. This method adds the provided consumer lambda to an anMouseListener
instance to the component.- 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 aComponentListener
to the component, to receive those component events where the wrapped component becomes 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 aComponentListener
to the component, to receive those component events where the wrapped component becomes invisible.- 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 wrapped 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:
-
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, state -> { double r = state.progress(); double g = 1 - state.progress(); double b = state.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 Object constraints) 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.- 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:
viewable
- 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 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.- Type Parameters:
M
- The type of the items in theVals
list.- Parameters:
viewables
- 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.
-
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.viewable
- 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 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.- 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.viewables
- 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.
-
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.viewable
- 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 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.- 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.viewables
- 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.
-
_addViewableProps
protected <M> void _addViewableProps(sprouts.Vals<M> models, @Nullable String attr, ViewSupplier<M> viewSupplier, C thisComponent) -
getType
The type class of the component managed by this builder. See documentation for method "build" for more information.- Returns:
- The type class of the component managed by this builder.
-
getComponent
Deprecated.Useget(Class)
instead.The component managed by this builder.- Returns:
- The component managed by this builder.
- Throws:
IllegalStateException
- if this method is called from a thread other than the EDT and this UI is configured to be decoupled from the application thread. SeeUIFactoryMethods.use(EventProcessor, Supplier)
.
-
component
Deprecated.Useget(Class)
instead.The optional component managed by this builder.- Returns:
- An
OptionalUI
wrapping a component or null. This optional will throw an exception if the application has an application thread (seeUIFactoryMethods.use(EventProcessor, Supplier)
) and this method is called from a thread other than the EDT.
-
peek
Use this if you wish to access the component wrapped by this builder directly. This is useful for more fine-grained control, like for example calling methods like "setName", "setTitle", and so on...
This method accepts a lambda to which the component wrapped by this builder will be supplied. The lambda can then call said methods or perform other tasks which might be relevant to the component while also not breaking the benefits of nesting and method chaining provided by this class...
The below example shows how this method allows for more fine-grained control over the wrapped component:UI.panel() peek( panel -> panel.setDebugGraphicsOptions(true) );
- Parameters:
action
- A Consumer lambda which simply returned the wrapped JComponent type for interacting it.- Returns:
- This very instance, which enables builder-style method chaining.
-
applyIf
Use this to only build a certain part of the UI if the provided boolean condition is true. Which is to say, if the condition is false, then the second lambda is ignored, if on the other hand the condition is true, then the second lambda is executed with the current builder instance passed to it as a parameter. Inside the lambda, one can then continue building the UI while also not breaking the benefits of nesting and method chaining provided by this builder...This is in essence a more advanced version of
apply(Consumer)
.
Here a simple usage example:
Here we use theis method to build a panel with different content depending on whether the user is logged in or not.UI.panel() .applyIf( userIsLoggedIn, ui -> ui .add( UI.label("Welcome back!") ) .add( UI.button("Logout")).onClick( () -> logout() ) .add( UI.button("Settings")).onClick( () -> showSettings() ) ) .applyIf( !userIsLoggedIn, ui -> ui .add( UI.label("Please login to continue.") ) .add( UI.button("Login")).onClick( () -> login() ); );
- Parameters:
condition
- The truth value which determines if the second consumer lambda is executed or not.building
- AConsumer
lambda which simply consumes this builder instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
applyIfPresent
Allows you to build declarative UI conditionally, meaning that the UI is only built if the providedOptional
value is present. If the value is not present, meaning it is null, then the second lambda (containing UI declarations relevant to the value) is simply ignored.Consider the following example:
The// In your view model: public Optional<MySubModel> getM() { return Optional.ofNullable(this.model); } // In your view: UI.panel() .add(UI.label("Maybe Sub Model:")) .applyIfPresent(vm.getM().map(m->ui->ui .add(UI.label("Hello Sub Model!")) .add(UI.label("A:") .add(UI.textField(m.getA())) .add(UI.label("B:")) .add(UI.textField(m.getB())) // ... )) .add(UI.label("Some other stuff..."));
applyIfPresent
method takes anOptional<Consumer<I>>
as parameter, whereI
is the type of the UI builder. This allows you to map the optional value to a consumer which is only executed if the value is present. If the optional value is present, the consumer is executed with the current UI builder as a parameter, which allows you to continue building the UI as usual.
Them->ui->ui
may look a bit confusing at first, but it is simply a lambda expression which takes the optional value and returns a consumer (ui->ui...
) which takes the UI builder as a parameter.
This is in essence a more advancedOptional
centric version ofapplyIf(boolean, Consumer)
andapply(Consumer)
.- Parameters:
building
- An optional consumer lambda which simply consumes this builder node.- Returns:
- This very instance, which enables builder-style method chaining.
-
apply
Use this to continue building UI inside a provided lambda if you need to introduce some imperative code in between the building process.
This is especially useful for when you need to build UI based on loops. The current builder instance will simply be supplied to the providedConsumer
lambda. Inside the supplied lambda, you can then continue building the UI while also not breaking the benefits of nesting and method chaining, effectively preserving the declarative nature of the builder.
Here is a simple example of how this method can be used to build a panel with a variable amount of images displayed in a grid:UI.panel("wrap 3") .apply( ui -> { for ( String path : imagePaths ) ui.add( UI.label(UI.icon(path)) ); });
Here is another example of how this method can be used to build a panel with a variable amount of buttons displayed in a grid:UI.panel("wrap 4") .apply( ui -> { for ( int i = 0; i < numOfButtons; i++ ) ui.add( UI.button("Button " + i) .onClick( () -> {...} ); });
- Parameters:
building
- A Consumer lambda which simply consumes this builder instance.- Returns:
- This very instance, which enables builder-style method chaining.
-
get
This method completes the building process for the wrappedJComponent
type by returning it. However, it also expects the user to pass the class of theJComponent
wrapped by this builder! This is not out of necessity but for better readability when using the builder in more extensive ways where the beginning and end of the method chaining and nesting of the builder does not fit on one screen.
In such cases the expression ".get(MyJComponent.class)
" helps to identify which type ofJComponent
is currently being built on a given nesting layer...
Here is a simple example that demonstrates this technique using aJPanel
and aJMenuBar
:
As you can see, the expression "UI.panel() .add( UI.menuBar() .add( UI.menu("File") ) .add( UI.menuItem("Open") ) .add( UI.menuItem("Save") ) // ... .add( UI.menuItem("Exit") ) .get(JMenuBar.class) ) .add( UI.button("Click me!") ) .get(JPanel.class);
.get(JMenuBar.class)
" as well as the expression ".get(JPanel.class)
" at the end of the builder chain help to identify which type ofJComponent
is currently being built and returned.- Parameters:
type
- The type class of the component which this builder wraps.- Returns:
- The result of the building process, namely: a type of JComponent.
-
add
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.- Parameters:
components
- An array of component instances which ought to be added to the wrapped component type.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
Uses the supplied builder to build its component and then add it to the component that is being built by this builder instance. This directly allows you to nest your builder based UI declarations in an HTML-like fashion.- Type Parameters:
T
- The type of theJComponent
which is wrapped by the provided builder.- Parameters:
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
@SafeVarargs public final <B extends swingtree.UIForAnything<?,?, I addJComponent>> (B... builders) This method provides the same functionality as the other "add" methods. However, it bypasses the necessity to call the "get" method by calling it internally for you.
This helps to improve readability, especially when the degree of nesting is very low.- Type Parameters:
B
- The type of the builder instances which are used to configure the components that will be added to the component wrapped by this builder.- Parameters:
builders
- An array of builder instances whose JComponents ought to be added to the one wrapped by this builder.- Returns:
- This very instance, which enables builder-style method chaining.
-
add
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.- Parameters:
components
- A list of component instances which ought to be added to the wrapped component type.- Returns:
- This very instance, which enables builder-style method chaining.
-
_addBuildersTo
@SafeVarargs protected final <B extends swingtree.UIForAnything<?,?, void _addBuildersToJComponent>> (C thisComponent, B... builders) -
_addComponentsTo
@SafeVarargs protected final void _addComponentsTo(C thisComponent, JComponent... componentsToBeAdded) -
_addBuilderTo
-
_state
Returns the state of the builder, which is a container for the wrapped component as well as it's type and currentEventProcessor
.- Returns:
- The state of the builder.
-
_newBuilderWithState
protected abstract swingtree.UIForAnything<I,C, _newBuilderWithStateJComponent> (swingtree.BuilderState<C> newState) An internal wither method which creates a new builder instance with the providedBuilderState
stored inside it.- Parameters:
newState
- The new state which should be stored inside the new builder instance.- Returns:
- A new builder instance with the provided state stored inside it.
-
_with
Creates a new builder with the provided component mutation applied to the wrapped component.
Note that the SwingTree builders are immutable, which means that this method does not mutate the current builder instance, but instead creates a new builder instance with a newBuilderState
which contains the provided component mutation (seeBuilderState.withMutator(Consumer)
). Also see_newBuilderWithState(BuilderState)
.- Parameters:
componentMutator
- A consumer lambda which receives the wrapped component and is then used to apply some builder action to it.- Returns:
- A new builder instance with the provided component mutation applied to the wrapped component.
-
_runInUI
A convenient shortcut to theEventProcessor.registerUIEvent(Runnable)
method to the currentEventProcessor
attached to the currentBuilderState
. In practice, this method will ultimately just delegate tasks to the AWT Event Dispatch Thread (EDT).- Parameters:
action
- An action which should be executed by the UI thread, which is determined by implementations of theEventProcessor
, also seeUIFactoryMethods.use(EventProcessor, Supplier)
.
Usually the UI thread is AWT's Event Dispatch Thread (EDT).
-
_runInApp
A convenient delegate to theEventProcessor.registerAppEvent(Runnable)
method, which allows you to execute an action on the current application thread. To configure the currentEventProcessor
seeUIFactoryMethods.use(EventProcessor, Supplier)
or the underlyingSwingTree.setEventProcessor(EventProcessor)
method.- Parameters:
action
- An action which should be executed by the application thread, which is determined by implementations of the currentEventProcessor
, also seeUIFactoryMethods.use(EventProcessor, Supplier)
.
-
_runInApp
A convenient delegate to theEventProcessor.registerAppEvent(Runnable)
method, which allows you to execute an action on the current application thread. Which thread executes these tasks is determined by the currentEventProcessor
. Usually this is theEventProcessor.COUPLED
orEventProcessor.COUPLED_STRICT
event processor.- Type Parameters:
T
- The type of the value.- Parameters:
value
- A value which should be captured and then passed to the provided action on the current application thread (seeEventProcessor
andUIFactoryMethods.use(EventProcessor, Supplier)
).action
- A consumer lambda which is executed by the application thread and receives the provided value.
-
_onShow
protected final <T> void _onShow(sprouts.Val<T> val, C thisComponent, BiConsumer<C, T> displayAction) Use this to register a state change listener for the provided property which will be executed by the UI thread (seeEventProcessor
).- Type Parameters:
T
- The type of the item wrapped by the provided property.- Parameters:
val
- A property whose state changes should be listened to on the UI thread.thisComponent
- The component which is wrapped by this builder.displayAction
- A consumer lambda receiving the provided value and is then executed by the UI thread.
-
_withOnShow
protected final <T> swingtree.UIForAnything<I,C, _withOnShowJComponent> (sprouts.Val<T> val, BiConsumer<C, T> displayAction) -
_onShow
protected final <T> void _onShow(sprouts.Vals<T> vals, C c, BiConsumer<C, sprouts.ValsDelegate<T>> displayAction) Use this to register a state change listener for the provided property list which will be executed by the UI thread (seeEventProcessor
).- Type Parameters:
T
- The type of the items wrapped by the provided property list.- Parameters:
vals
- A property list whose state changes should be listened to on the UI thread.c
- The component which is wrapped by this builder.displayAction
- A consumer lambda receiving the action delegate and is then executed by the UI thread.
-
_withOnShow
protected final <T> swingtree.UIForAnything<I,C, _withOnShowJComponent> (sprouts.Vals<T> vals, BiConsumer<C, sprouts.ValsDelegate<T>> displayAction) -
_this
Exposes the this-pointer of the builder instance cast to theI
type parameter of the builder class.
This is done to reduce the amount of type casting and warnings in the codebase.- Returns:
- The builder instance itself based on the type parameter
<I>
.
-
_disposeState
protected final void _disposeState()This method is used to dispose of the state of the builder, which means that the builder state disposes of its reference to either the wrapped component or the wrapped component or the composite of component factories which are used to build the wrapped component eagerly each time the wrapped component is accessed.
This is important to avoid memory leaks, as a component is typically part of a tree of components, and if one component is not garbage collected, then the whole tree is not garbage collected. -
hashCode
public final int hashCode() -
equals
-
toString
-
get(Class)
instead.