Class UIForAnyButton<I,B extends AbstractButton>
- Type Parameters:
I- The type parameter for the instance type of this concrete class itself.B- The type parameter for the component wrapped by an instance of this class.
- Direct Known Subclasses:
UIForAnyMenuItem,UIForAnyToggleButton,UIForButton,UIForCheckBox,UIForSplitButton
UIForAnySwing builder type,
and provides additional features associated with the more specialized
AbstractButton" Swing component type.
One of such features is the onClick(Action) method allowing for a more readable way of adding
ActionListener instances to button types...
Please take a look at the living swing-tree documentation
where you can browse a large collection of examples demonstrating how to use the API of this class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidprotected final void_onClick(B button, Consumer<ActionEvent> action) protected final void_onModelChange(B button, Consumer<ChangeEvent> action) isBorderPaintedIf(boolean borderPainted) Sets theAbstractButton.setBorderPainted(boolean)flag of the wrapped button type.isBorderPaintedIf(sprouts.Val<Boolean> val) Binds the providedValproperty to theAbstractButton.setBorderPainted(boolean)method., which means that whenever the value of the property changes, the border of the button will be painted or not.final IisPressedIf(sprouts.Var<Boolean> var) Use this to dynamically bind to aVarinstance which will be used to dynamically model the pressed state of the wrappedAbstractButtontype.final IisSelectedIf(boolean isSelected) Use this to set the selection state of the wrapped button type.final IisSelectedIf(sprouts.Val<Boolean> selected) Use this to bind to aVarinstance which will be used to dynamically model the selection state of the wrappedAbstractButtontype.final IisSelectedIf(sprouts.Var<Boolean> selected) Use this to bind to aVarinstance which will be used to dynamically model the selection state of the wrappedAbstractButtontype.final <T> IisSelectedIf(T state, sprouts.Val<T> selection) Use this to dynamically bind the selection flag of the button to aValproperty which will determine the selection state of the button based on the equality of the property value and the provided reference value.final IisSelectedIfNot(sprouts.Val<Boolean> selected) Use this to bind to aVarinstance which will be used to dynamically model the inverse selection state of the wrappedAbstractButtontype.final IisSelectedIfNot(sprouts.Var<Boolean> selected) Use this to dynamically bind to aVarinstance which will be used to dynamically model the inverse selection state of the wrappedAbstractButtontype.final <T> IisSelectedIfNot(T state, sprouts.Val<T> selection) This is the inverse ofisSelectedIf(Object, Val).final IEffectively removes the native style of this button.final IonChange(sprouts.Action<ComponentDelegate<B, ItemEvent>> action) This method adds the providedItemListenerinstance to the wrapped button component.onClick(sprouts.Action<ComponentDelegate<B, ActionEvent>> action) This method enables a more readable way of addingActionListenerinstances to button types.final IwithButtonGroup(ButtonGroup group) Use this to attach this button type to a button group.final IUse this to set the font of the wrapped button type.final IUse this to dynamically set the font of the wrapped button type through the provided view model property.withFontSize(int size) Use this to set the size of the font of the wrapped button type.withFontSize(sprouts.Val<Integer> size) Use this to dynamically set the size of the font of the wrapped button type through the provided view model property.final IwithHorizontalAlignment(sprouts.Val<UI.HorizontalAlignment> horizontalAlign) A convenience method to avoid peeking into this builder like so:final IwithHorizontalAlignment(UI.HorizontalAlignment horizontalAlign) A convenience method to avoid peeking into this builder like so:final IwithHorizontalTextAlignment(sprouts.Val<UI.HorizontalAlignment> horizontalAlign) A convenience method to avoid peeking into this builder like so:final IwithHorizontalTextAlignment(UI.HorizontalAlignment horizontalAlign) A convenience method to avoid peeking into this builder like so:Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type.
Also seewithIcon(int, int, IconDeclaration), which is the preferred way of setting icons on buttons!withIcon(int width, int height, IconDeclaration icon) Takes the providedIconDeclarationand scales it to the provided width and height before displaying it on the wrapped button type.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIcon(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.Use this to set the icon for the wrapped button type.withIcon(Icon icon, UI.FitComponent fitComponent) Sets theIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIcon(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the icon property for the wrapped button type.withIcon(IconDeclaration icon) Use this to specify the icon for the wrapped button type.withIcon(IconDeclaration icon, UI.FitComponent fitComponent) Sets theIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnDisabled(int width, int height, Icon icon) Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is disabled.
Also seewithIconOnDisabled(int, int, IconDeclaration), which is the preferred way of setting disabled icons on buttons!withIconOnDisabled(int width, int height, IconDeclaration icon) Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when disabled.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIconOnDisabled(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when disabled by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIconOnDisabled(Icon icon) Use this to set the "disabled" icon for the wrapped button type.withIconOnDisabled(Icon icon, UI.FitComponent fitComponent) Sets the disabledIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnDisabled(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the "disabled icon" property for the wrapped button type, which is displayed when the button is disabled.Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is disabled.withIconOnDisabled(IconDeclaration icon, UI.FitComponent fitComponent) Sets the disabledIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnDisabledAndSelected(int width, int height, Icon icon) Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is both disabled and selected.
Also seewithIconOnDisabledAndSelected(int, int, IconDeclaration), which is the preferred way of setting disabled and selected icons on buttons!withIconOnDisabledAndSelected(int width, int height, IconDeclaration icon) Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when both disabled and selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIconOnDisabledAndSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when both disabled and selected by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.Use this to set the "disabled and selected" icon for the wrapped button type.withIconOnDisabledAndSelected(Icon icon, UI.FitComponent fitComponent) Sets the disabled and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnDisabledAndSelected(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the "disabled and selected icon" property for the wrapped button type, which is displayed when the button is both disabled and selected.Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is both disabled and selected.withIconOnDisabledAndSelected(IconDeclaration icon, UI.FitComponent fitComponent) Sets the disabled and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnHover(int width, int height, Icon icon) Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the user hovers their cursor over the button type.
Also seewithIconOnHover(int, int, IconDeclaration), which is the preferred way of setting hover icons on buttons!withIconOnHover(int width, int height, IconDeclaration icon) Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type whenever the user hovers their cursor over the button.withIconOnHover(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the suppliedIconDeclarationand scales the corresponding icon it to the desired width and height after which it uses theUI.FitComponentlayout policy enum constant to display it on the wrapped button type whenever the user hovers their cursor over the button...
Note that thewidthandheightproperties only serve as reference values as theUI.FitComponentis used to resize the icon to fit the component.withIconOnHover(Icon icon) Use this to set the "hovered" icon for the wrapped button type, which translates toAbstractButton.setRolloverIcon(Icon)of the underlying button component, but with additional UI scalability guarantees.withIconOnHover(Icon icon, UI.FitComponent fitComponent) Sets the hoverIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnHover(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the "hovered icon" property for the wrapped button type, which is displayed when the user hovers their cursor over the button area.Use this to specify the icon for the wrapped button type, which ought to be displayed temporarily whenever the user has their cursor hovering over the button area.withIconOnHover(IconDeclaration icon, UI.FitComponent fitComponent) Sets the hoverIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnHoverAndSelected(int width, int height, Icon icon) Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is both rolled over and selected.
Also seewithIconOnHoverAndSelected(int, int, IconDeclaration), which is the preferred way of setting rollover and selected icons on buttons!withIconOnHoverAndSelected(int width, int height, IconDeclaration icon) Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when both rolled over and selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIconOnHoverAndSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when both rolled over and selected by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.Use this to set the "rollover and selected" icon for the wrapped button type.withIconOnHoverAndSelected(Icon icon, UI.FitComponent fitComponent) Sets the rollover and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnHoverAndSelected(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the "rollover and selected icon" property for the wrapped button type, which is displayed when the button is both rolled over and selected.Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is both rolled over and selected.withIconOnHoverAndSelected(IconDeclaration icon, UI.FitComponent fitComponent) Sets the rollover and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnPress(int width, int height, Icon icon) Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the user presses the button type.
Also seewithIconOnPress(int, int, IconDeclaration), which is the preferred way of setting icons on buttons!withIconOnPress(int width, int height, IconDeclaration icon) Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when pressed.withIconOnPress(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when pressed by the user.withIconOnPress(Icon icon) Use this to set the "pressed" icon for the wrapped button type.withIconOnPress(Icon icon, UI.FitComponent fitComponent) Sets the pressedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnPress(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the "pressed icon" property for the wrapped button type, which is displayed when the user presses and holds the button.Use this to specify the icon for the wrapped button type, which ought to be displayed temporarily when the user presses the button.withIconOnPress(IconDeclaration icon, UI.FitComponent fitComponent) Sets the pressedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnSelected(int width, int height, Icon icon) Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is selected.
Also seewithIconOnSelected(int, int, IconDeclaration), which is the preferred way of setting selected icons on buttons!withIconOnSelected(int width, int height, IconDeclaration icon) Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIconOnSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when selected by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.withIconOnSelected(Icon icon) Use this to set the "selected" icon for the wrapped button type.withIconOnSelected(Icon icon, UI.FitComponent fitComponent) Sets the selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.withIconOnSelected(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the "selected icon" property for the wrapped button type, which is displayed when the button is selected.Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is selected.withIconOnSelected(IconDeclaration icon, UI.FitComponent fitComponent) Sets the selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy.final IwithMargin(int top, int left, int bottom, int right) Use this to set the margin of the wrapped button type.final IwithMargin(Insets insets) Use this to set the margin of the wrapped button type.final IDefines the single line of text the wrapped button type will display.final IBinds the providedValproperty to the wrapped button type and sets the text of the button to the value of the property.final IwithVerticalAlignment(sprouts.Val<UI.VerticalAlignment> verticalAlign) A convenience method to avoid peeking into this builder like so:final IwithVerticalAlignment(UI.VerticalAlignment verticalAlign) A convenience method to avoid peeking into this builder like so:final IwithVerticalTextAlignment(sprouts.Val<UI.VerticalAlignment> verticalAlign) A convenience method to avoid peeking into this builder like so:final IwithVerticalTextAlignment(UI.VerticalAlignment verticalAlign) A convenience method to avoid peeking into this builder like so:Methods inherited from class swingtree.UIForAnySwing
_addComponentTo, _addViewableProps, _addViewableProps, _addViewableProps, _isUndefinedColor, _isUndefinedFont, _setBackground, _setEnabled, _setMinHeight, _setMinWidth, _setPrefWidth, _tryCalculatingDiffBetween, add, add, add, add, add, add, add, add, add, add, addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAll, doUpdates, group, group, id, id, isEnabledIf, isEnabledIf, isEnabledIf, isEnabledIfNot, isEnabledIfNot, isEnabledIfNot, isFocusableIf, isFocusableIf, isFocusableIf, isFocusableIfNot, isFocusableIfNot, isFocusableIfNot, isValidIf, isVisibleIf, isVisibleIf, isVisibleIf, isVisibleIfNot, isVisibleIfNot, isVisibleIfNot, makeFocused, makeNonOpaque, makeOpaque, on, on, onCharTyped, onFocusGain, onFocusLoss, onHidden, onKeyPress, onKeyRelease, onKeyTyped, onMouseClick, onMouseDrag, onMouseEnter, onMouseEnter, onMouseEnterGreedy, onMouseExit, onMouseExit, onMouseExitGreedy, onMouseMove, onMousePress, onMouseRelease, onMouseWheelDown, onMouseWheelMove, onMouseWheelUp, onMoved, onPressed, onRelease, onResize, onShown, onTyped, onTyped, onView, withBackground, withBackground, withBackgroundColor, withBackgroundIf, withBackgroundIf, withBackgroundIf, withBackgroundIf, withBorder, withBorder, withBorderTitled, withBorderTitled, withBoxLayout, withCompoundBorder, withCompoundBorderTitled, withCursor, withCursor, withCursorIf, withCursorIf, withDragAway, withDropSite, withEmptyBorder, withEmptyBorder, withEmptyBorder, withEmptyBorder, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withFlowLayout, withFlowLayout, withFlowLayout, withForeground, withForeground, withForegroundColor, withForegroundIf, withForegroundIf, withForegroundIf, withForegroundIf, withGridBagLayout, withGridLayout, withGridLayout, withGridLayout, withHeight, withHeight, withHeightExactly, withHeightExactly, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLineBorder, withLineBorder, withLineBorder, withLineBorderTitled, withLineBorderTitled, withLineBorderTitled, withLineBorderTitled, withMatteBorder, withMatteBorder, withMatteBorder, withMatteBorderTitled, withMatteBorderTitled, withMatteBorderTitled, withMaxHeight, withMaxHeight, withMaxSize, withMaxSize, withMaxSize, withMaxSize, withMaxSize, withMaxWidth, withMaxWidth, withMinHeight, withMinHeight, withMinSize, withMinSize, withMinSize, withMinSize, withMinSize, withMinWidth, withMinWidth, withPrefHeight, withPrefHeight, withPrefSize, withPrefSize, withPrefSize, withPrefSize, withPrefSize, withPrefWidth, withPrefWidth, withProperty, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withSize, withSize, withSize, withSize, withSizeExactly, withSizeExactly, withSizeExactly, withSizeExactly, withStyle, withTooltip, withTooltip, withTransitionalStyle, withTransitoryStyle, withWidth, withWidth, withWidthExactly, withWidthExactlyMethods inherited from class swingtree.UIForAnything
_addBuildersTo, _addBuilderTo, _addComponentsTo, _disposeState, _newBuilderWithState, _onShow, _onShow, _onShowDelegated, _runInApp, _runInApp, _runInUI, _state, _this, _with, _withOnShow, _withOnShow, add, add, add, add, apply, applyIf, applyIfPresent, component, equals, get, getComponent, getType, hashCode, peek, toString
-
Constructor Details
-
UIForAnyButton
public UIForAnyButton()
-
-
Method Details
-
withText
Defines the single line of text the wrapped button type will display. If the value of text is null or empty string, nothing is displayed.- Parameters:
text- The new text to be set for the wrapped button type.- Returns:
- This very builder to allow for method chaining.
-
withText
Binds the providedValproperty to the wrapped button type and sets the text of the button to the value of the property. Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to manually send the property value to this view component.- Parameters:
text- The view model property which should be bound to this UI.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- iftextisnull.
-
withIcon
Use this to set the icon for the wrapped button type. For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> button.setIcon(...) );UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also seewithIcon(IconDeclaration), which is the recommended way of setting icons on buttons!- Parameters:
icon- TheIconwhich should be displayed on the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ificonisnull.
-
withIcon
Use this to specify the icon for the wrapped button type. The icon is determined based on the providedIconDeclarationinstance which is conceptually merely a resource path to the icon. For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Click me!") .peek( button -> icon.find().ifPresent(button::setIcon) );UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments.- Parameters:
icon- The desired icon to be displayed on top of the button.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Use this to dynamically set the icon property for the wrapped button type. When theIconDeclarationwrapped by the provided property changes, then so does the icon displayed on this button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setIcon) ));UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed on the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ificonisnull.
-
withIcon
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type.
Also seewithIcon(int, int, IconDeclaration), which is the preferred way of setting icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and displayed on the button.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Takes the providedIconDeclarationand scales it to the provided width and height before displaying it on the wrapped button type.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich should be scaled and displayed on the button.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconDeclaration, whose referenced icon will be scaled and displayed on the button.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Sets theIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is also used as the "pressed" and "disabled" icon if there is no explicitly set pressed icon.
Please also seewithIcon(IconDeclaration, UI.FitComponent), which is the recommended way of setting icons on buttons!- Parameters:
icon- TheIconwhich should be displayed on the button. Ideally, this should be anSvgIconto ensure thatUI.FitComponentcan be applied properly.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled to fit the component.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Sets theIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is also used as the "pressed" and "disabled" icon if no other icon type is explicitly set. This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- TheIconDeclarationwhich should be displayed on the button.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
-
withIconOnPress
Use this to set the "pressed" icon for the wrapped button type. This is in essence a convenience method to avoid peeking into this builder like so:
Please also seeUI.button("Something") .peek( button -> button.setPressedIcon(...) );withIconOnPress(IconDeclaration), which is the recommended way of setting icons on buttons!- Parameters:
icon- TheIconwhich should be displayed when the button is pressed.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnPress
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the user presses the button type.
Also seewithIconOnPress(int, int, IconDeclaration), which is the preferred way of setting icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and then displayed when the button is being pressed.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnPress
Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when pressed. This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich should be scaled and then displayed when the button is being pressed.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnPress
Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when pressed by the user.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconwhich should be scaled and then displayed when the button is being pressed.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnPress
Sets the pressedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the user presses the button type.
Please also seewithIconOnPress(IconDeclaration, UI.FitComponent), which is the recommended way of setting pressed icons on buttons!- Parameters:
icon- TheSvgIconwhich should be displayed when the button is being pressed.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnPress
Sets the pressedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed temporarily when the user presses and holds the button.- Parameters:
icon- TheIconDeclarationwhich should be displayed when the button is being pressed.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnPress
Use this to specify the icon for the wrapped button type, which ought to be displayed temporarily when the user presses the button. The icon is resolved based on the suppliedIconDeclarationinstance which serves as a resource path to the icon actual.- Parameters:
icon- The desired icon to be displayed on top of the button for when it is being pressed.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnPress
Use this to dynamically set the "pressed icon" property for the wrapped button type, which is displayed when the user presses and holds the button. When the icon wrapped by the suppliedValproperty changes, then so does the pressed icon of this button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the pressed icon on the component, this method will also try to load and install the icon as a scalableUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setPressedIcon) ));ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed when the button is being pressed.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnHover
Use this to set the "hovered" icon for the wrapped button type, which translates toAbstractButton.setRolloverIcon(Icon)of the underlying button component, but with additional UI scalability guarantees. In most cases this is a convenience method to avoid peeking into this builder like so:
But in addition to simply setting the hover/rollover icon on the component, it will also try to convert it to an icon variant which scales according to theUI.button("Something") .peek( button -> button.setRolloverIcon(...) );UI.scale()factor. Please also seewithIconOnHover(IconDeclaration), which is the recommended way of setting icons on buttons!- Parameters:
icon- TheIconwhich should be displayed when the cursor hovers over the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnHover
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the user hovers their cursor over the button type.
Also seewithIconOnHover(int, int, IconDeclaration), which is the preferred way of setting hover icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and then displayed when the button is being hovered over.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnHover
Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type whenever the user hovers their cursor over the button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
In case of the referenced icon being an SVG file, the icon will be loaded as a fully scalableUI.button("Click me!") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.withSize(width,height) .find() .ifPresent(button::setRolloverIcon) ));SvgIcon, if it is a png or jpeg file however, this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich whose icon should be scaled and then displayed when the button is being hovered over.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnHover
Takes the suppliedIconDeclarationand scales the corresponding icon it to the desired width and height after which it uses theUI.FitComponentlayout policy enum constant to display it on the wrapped button type whenever the user hovers their cursor over the button...
Note that thewidthandheightproperties only serve as reference values as theUI.FitComponentis used to resize the icon to fit the component.In case of the referenced icon being an SVG file, the icon will be loaded as a fully scalable
SvgIcon, if it is a png or jpeg file however, this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconwhich should be scaled and then displayed when the button is being hovered over.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnHover
Sets the hoverIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the user hovers their cursor over the button type.
Please also seewithIconOnHover(IconDeclaration, UI.FitComponent), which is the recommended way of setting hover icons on buttons!- Parameters:
icon- TheSvgIconwhich should be displayed when the button is being hovered over.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnHover
Sets the hoverIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed temporarily when the user hovers their mouse cursor over the button area.- Parameters:
icon- TheIconDeclarationwhich should be displayed when the button is being hovered over.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnHover
Use this to specify the icon for the wrapped button type, which ought to be displayed temporarily whenever the user has their cursor hovering over the button area. The icon is resolved based on the suppliedIconDeclarationinstance which serves as a resource path to the icon actual.- Parameters:
icon- The desired icon to be displayed on top of the button for when it is being hovered over.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnHover
Use this to dynamically set the "hovered icon" property for the wrapped button type, which is displayed when the user hovers their cursor over the button area. When the icon wrapped by the suppliedValproperty changes, then so does the "hover icon" of this button. Or more specifically, theAbstractButton.getRolloverIcon()property of the underlying component.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the rollover icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setRolloverIcon) ));UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should always use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed when the button is being hovered over.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnHoverAndSelected
Use this to set the "rollover and selected" icon for the wrapped button type. This is in essence a convenience method to avoid peeking into this builder like so:
But in addition to simply setting the rollover and selected icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> button.setRolloverSelectedIcon(...) );UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also seewithIconOnHoverAndSelected(IconDeclaration), which is the recommended way of setting rollover and selected icons on buttons!- Parameters:
icon- TheIconwhich should be displayed when the button is both rolled over and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnHoverAndSelected
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is both rolled over and selected.
Also seewithIconOnHoverAndSelected(int, int, IconDeclaration), which is the preferred way of setting rollover and selected icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and then displayed when the button is both rolled over and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnHoverAndSelected
Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when both rolled over and selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich should be scaled and then displayed when the button is both rolled over and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnHoverAndSelected
public I withIconOnHoverAndSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when both rolled over and selected by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconwhich should be scaled and then displayed when the button is both rolled over and selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnHoverAndSelected
Sets the rollover and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is both rolled over and selected.
Please also seewithIconOnHoverAndSelected(IconDeclaration, UI.FitComponent), which is the recommended way of setting rollover and selected icons on buttons!- Parameters:
icon- TheSvgIconwhich should be displayed when the button is both rolled over and selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnHoverAndSelected
Sets the rollover and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is both rolled over and selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- TheIconDeclarationwhich should be displayed when the button is both rolled over and selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnHoverAndSelected
Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is both rolled over and selected. The icon is resolved based on the suppliedIconDeclarationinstance which serves as a resource path to the icon actual.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- The desired icon to be displayed on top of the button for when it is both rolled over and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnHoverAndSelected
Use this to dynamically set the "rollover and selected icon" property for the wrapped button type, which is displayed when the button is both rolled over and selected. When the icon wrapped by the suppliedValproperty changes, then so does the rollover and selected icon of this button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the rollover and selected icon on the component, this method will also try to load and install the icon as a scalableUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setRolloverSelectedIcon) ));ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed when the button is both rolled over and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnSelected
Use this to set the "selected" icon for the wrapped button type. This is in essence a convenience method to avoid peeking into this builder like so:
But in addition to simply setting the selected icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> button.setSelectedIcon(...) );UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also seewithIconOnSelected(IconDeclaration), which is the recommended way of setting selected icons on buttons!- Parameters:
icon- TheIconwhich should be displayed when the button is selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnSelected
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is selected.
Also seewithIconOnSelected(int, int, IconDeclaration), which is the preferred way of setting selected icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and then displayed when the button is selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnSelected
Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich should be scaled and then displayed when the button is selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnSelected
public I withIconOnSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when selected by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconwhich should be scaled and then displayed when the button is selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnSelected
Sets the selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is selected.
Please also seewithIconOnSelected(IconDeclaration, UI.FitComponent), which is the recommended way of setting selected icons on buttons!- Parameters:
icon- TheSvgIconwhich should be displayed when the button is selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnSelected
Sets the selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- TheIconDeclarationwhich should be displayed when the button is selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnSelected
Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is selected. The icon is resolved based on the suppliedIconDeclarationinstance which serves as a resource path to the icon actual.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- The desired icon to be displayed on top of the button for when it is selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnSelected
Use this to dynamically set the "selected icon" property for the wrapped button type, which is displayed when the button is selected. When the icon wrapped by the suppliedValproperty changes, then so does the selected icon of this button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the selected icon on the component, this method will also try to load and install the icon as a scalableUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setSelectedIcon) ));ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed when the button is selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnDisabled
Use this to set the "disabled" icon for the wrapped button type. This is in essence a convenience method to avoid peeking into this builder like so:
But in addition to simply setting the disabled icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> button.setDisabledIcon(...) );UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also seewithIconOnDisabled(IconDeclaration), which is the recommended way of setting disabled icons on buttons!- Parameters:
icon- TheIconwhich should be displayed when the button is disabled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnDisabled
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is disabled.
Also seewithIconOnDisabled(int, int, IconDeclaration), which is the preferred way of setting disabled icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and then displayed when the button is disabled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnDisabled
Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when disabled.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich should be scaled and then displayed when the button is disabled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnDisabled
public I withIconOnDisabled(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when disabled by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconwhich should be scaled and then displayed when the button is disabled.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnDisabled
Sets the disabledIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is disabled.
Please also seewithIconOnDisabled(IconDeclaration, UI.FitComponent), which is the recommended way of setting disabled icons on buttons!- Parameters:
icon- TheSvgIconwhich should be displayed when the button is disabled.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnDisabled
Sets the disabledIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is disabled.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- TheIconDeclarationwhich should be displayed when the button is disabled.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnDisabled
Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is disabled. The icon is resolved based on the suppliedIconDeclarationinstance which serves as a resource path to the icon actual.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- The desired icon to be displayed on top of the button for when it is disabled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnDisabled
Use this to dynamically set the "disabled icon" property for the wrapped button type, which is displayed when the button is disabled. When the icon wrapped by the suppliedValproperty changes, then so does the disabled icon of this button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the disabled icon on the component, this method will also try to load and install the icon as a scalableUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setDisabledIcon) ));ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed when the button is disabled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnDisabledAndSelected
Use this to set the "disabled and selected" icon for the wrapped button type. This is in essence a convenience method to avoid peeking into this builder like so:
But in addition to simply setting the disabled and selected icon on the component, this method will also try to convert the icon to an icon variant which scales according to the currentUI.button("Something") .peek( button -> button.setDisabledSelectedIcon(...) );UI.scale()factor (seeScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also seewithIconOnDisabledAndSelected(IconDeclaration), which is the recommended way of setting disabled and selected icons on buttons!- Parameters:
icon- TheIconwhich should be displayed when the button is both disabled and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withIconOnDisabledAndSelected
Takes the providedIconand scales it to the provided width and height before displaying it on the wrapped button type when the button is both disabled and selected.
Also seewithIconOnDisabledAndSelected(int, int, IconDeclaration), which is the preferred way of setting disabled and selected icons on buttons!- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconwhich should be scaled and then displayed when the button is both disabled and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnDisabledAndSelected
Takes the suppliedIconDeclarationand scales it to the desired width and height before displaying it on the wrapped button type when both disabled and selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale().height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale().icon- TheIconDeclarationwhich should be scaled and then displayed when the button is both disabled and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnDisabledAndSelected
public I withIconOnDisabledAndSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent) Takes the providedIconDeclarationand scales the corresponding icon it to the provided width and height before displaying it on the wrapped button type when both disabled and selected by the user.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
width- The desired width of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.height- The desired height of the icon in "developer pixels", the actual width may be influenced byUI.scale()andUI.FitComponent.icon- TheIconwhich should be scaled and then displayed when the button is both disabled and selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled relative to the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnDisabledAndSelected
Sets the disabled and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is both disabled and selected.
Please also seewithIconOnDisabledAndSelected(IconDeclaration, UI.FitComponent), which is the recommended way of setting disabled and selected icons on buttons!- Parameters:
icon- TheSvgIconwhich should be displayed when the button is both disabled and selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnDisabledAndSelected
Sets the disabled and selectedIconproperty of the wrapped button type and scales it according to the providedUI.FitComponentpolicy. This icon is only displayed when the button is both disabled and selected.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- TheIconDeclarationwhich should be displayed when the button is both disabled and selected.fitComponent- TheUI.FitComponentwhich determines how the icon should be scaled.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- if any of the supplied arguments arenull!
-
withIconOnDisabledAndSelected
Use this to specify the icon for the wrapped button type, which ought to be displayed when the button is both disabled and selected. The icon is resolved based on the suppliedIconDeclarationinstance which serves as a resource path to the icon actual.
This method will try to load and install the icon as a scalableImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.- Parameters:
icon- The desired icon to be displayed on top of the button for when it is both disabled and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull!
-
withIconOnDisabledAndSelected
Use this to dynamically set the "disabled and selected icon" property for the wrapped button type, which is displayed when the button is both disabled and selected. When the icon wrapped by the suppliedValproperty changes, then so does the disabled and selected icon of this button.
For most scenarios, this is a convenience method equivalent to peeking into this builder like so:
But in addition to simply setting the disabled and selected icon on the component, this method will also try to load and install the icon as a scalableUI.button("Something") .peek( button -> iconProperty.onChange(From.ALL, icon -> icon.find().ifPresent(button::setDisabledSelectedIcon) ));ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalableSvgIcon, if it is a png or jpeg file however, then this method will represent it as aScalableImageIcon, which dynamically scales the underlying image according to theUI.scale()so that it has a proportionally correct size in high-dpi environments.But note that here you cannot use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful when writing unit tests for your view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.
- Parameters:
icon- TheIconproperty which should be displayed when the button is both disabled and selected.- Returns:
- This very builder to allow for method chaining.
- Throws:
NullPointerException- ificonisnull.
-
withFontSize
Use this to set the size of the font of the wrapped button type.- Parameters:
size- The size of the font which should be displayed on the button.- Returns:
- This very builder to allow for method chaining.
-
withFontSize
Use this to dynamically set the size of the font of the wrapped button type through the provided view model property. When the integer wrapped by the provided property changes, then so does the font size of the text displayed on this button.- Parameters:
size- The size property of the font which should be displayed on the button.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifsizeisnull.
-
withFont
Use this to set the font of the wrapped button type.- Parameters:
font- The font of the text which should be displayed on the button.- Returns:
- This builder instance, to allow for method chaining.
- Throws:
IllegalArgumentException- iffontisnull.
-
withFont
Use this to dynamically set the font of the wrapped button type through the provided view model property. When the font wrapped by the provided property changes, then so does the font of the text displayed on this button.- Parameters:
font- The font property of the text which should be displayed on the button type.- Returns:
- This builder instance, to allow for method chaining.
- Throws:
IllegalArgumentException- iffontisnull.IllegalArgumentException- iffontis a property which can wrapnull.
-
isSelectedIf
Use this to set the selection state of the wrapped button type.- Parameters:
isSelected- The selection state of the wrapped button type, which translates toAbstractButton.setSelected(boolean).- Returns:
- This builder instance, to allow for method chaining.
-
isSelectedIf
Use this to bind to aVarinstance which will be used to dynamically model the selection state of the wrappedAbstractButtontype.- Parameters:
selected- TheVarinstance which will be used to model the selection state of the wrapped button type.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifselectedisnull.
-
isSelectedIfNot
Use this to bind to aVarinstance which will be used to dynamically model the inverse selection state of the wrappedAbstractButtontype.- Parameters:
selected- TheVarinstance which will be used to model the inverse selection state of the wrapped button type.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifselectedisnull.
-
isSelectedIf
Use this to bind to aVarinstance which will be used to dynamically model the selection state of the wrappedAbstractButtontype.- Parameters:
selected- TheVarinstance which will be used to model the selection state of the wrapped button type.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifselectedisnull.
-
isSelectedIfNot
Use this to dynamically bind to aVarinstance which will be used to dynamically model the inverse selection state of the wrappedAbstractButtontype.- Parameters:
selected- TheVarinstance which will be used to model the inverse selection state of the wrapped button type.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifselectedisnull.
-
isSelectedIf
Use this to dynamically bind the selection flag of the button to aValproperty which will determine the selection state of the button based on the equality of the property value and the provided reference value. So if the firststateargument is equal to the value of theselectionproperty, the button will be selected, otherwise it will be deselected.
A typical use case is to bind a button to an enum property, like so:
As you can see, the radio button will be selected if the enum property is equal to the supplied enum value and deselected otherwise.// In your view model: enum Step { ONE, TWO, THREE } Var<Step> step = Var.of(Step.ONE); // In your view: UI.radioButton("Two").isSelectedIf(Step.TWO, vm.getStep());
Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to send the property value to this view component.- Type Parameters:
T- The type of the property value.- Parameters:
state- The reference value which the button type should represent when selected.selection- TheValinstance which will be used to dynamically model the selection state of the wrapped button type based on the equality of thestateargument and the value of the property.- Returns:
- The current builder type, to allow for further method chaining.
- Throws:
IllegalArgumentException- ifselectedisnull.
-
isSelectedIfNot
This is the inverse ofisSelectedIf(Object, Val). Use this to make the wrapped UI component dynamically deselected or selected, based on the equality between the supplied value and the property value.
Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to send the property value to this view component.
A typical use case is to bind to an enum property, like so:
As you can see, the radio button will be selected if the enum property is equal to the supplied enum value and deselected otherwise.// In your view model: enum Step { ONE, TWO, THREE } Var<Step> step = Var.of(Step.ONE); // In your view: UI.radioButton("Not Two") .isSelectedIfNot(Step.TWO, vm.getStep());- Type Parameters:
T- The type of the value.- Parameters:
state- The value which, if equal to the supplied property value, makes the UI component deselected.selection- The enum property which, if equal to the supplied value, makes the UI component deselected.- Returns:
- This very instance, which enables builder-style method chaining.
-
isPressedIf
Use this to dynamically bind to aVarinstance which will be used to dynamically model the pressed state of the wrappedAbstractButtontype.- Parameters:
var- TheVarinstance which will be used to model the pressed state of the wrapped button type.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifvarisnull.
-
_onModelChange
-
isBorderPaintedIf
Sets theAbstractButton.setBorderPainted(boolean)flag of the wrapped button type. If the flag is set to true, the border of the button will be painted. The default value for the borderPainted property is true. Some look and feels might not support the borderPainted property, in which case they ignore this.- Parameters:
borderPainted- Whether the border of the button should be painted.- Returns:
- This very instance, which enables builder-style method chaining.
-
isBorderPaintedIf
Binds the providedValproperty to theAbstractButton.setBorderPainted(boolean)method., which means that whenever the value of the property changes, the border of the button will be painted or not. The default value for the borderPainted property is true. Some look and feels might not support the borderPainted property, in which case they ignore this.- Parameters:
val- Whether the border of the button should be painted.- Returns:
- This very instance, which enables builder-style method chaining.
-
makePlain
Effectively removes the native style of this button. Without an icon or text, one will not be able to recognize the button. Use this for buttons with a custom icon or clickable text!- Returns:
- This very instance, which enables builder-style method chaining.
-
onChange
- Parameters:
action- The change action lambda which will be passed to the button component.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifactionisnull.
-
_onChange
-
onClick
This method enables a more readable way of addingActionListenerinstances to button types. Additionally, to the other "onClick" method this method enables the involvement of theJComponentitself into the action supplied to it. This is very useful for changing the state of the JComponent when the action is being triggered.- Parameters:
action- anActioninstance which will receive anComponentDelegatecontaining important context information.- Returns:
- This very instance, which enables builder-style method chaining.
- Throws:
IllegalArgumentException- ifactionisnull.
-
_onClick
-
withHorizontalAlignment
A convenience method to avoid peeking into this builder like so:
This sets the horizontal alignment of the icon and text.UI.button("Clickable!") .peek( button -> button.setHorizontalAlignment(...) );- Parameters:
horizontalAlign- The horizontal alignment which should be applied to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifhorizontalAlignisnull.
-
withHorizontalAlignment
A convenience method to avoid peeking into this builder like so:
This sets the horizontal alignment of the icon and text and also binds the provided property to the underlying component.UI.button("Clickable!") .peek( button -> { property.onSetItem(v->button.setHorizontalAlignment(v.forSwing())); button.setHorizontalAlignment(property.get().forSwing()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to send the property value to this view component.- Parameters:
horizontalAlign- The horizontal alignment property which should be bound to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifhorizontalAlignisnull.
-
withVerticalAlignment
A convenience method to avoid peeking into this builder like so:
This sets the vertical alignment of the icon and text.UI.button("Clickable!") .peek( button -> button.setVerticalAlignment(...) );- Parameters:
verticalAlign- The vertical alignment which should be applied to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifverticalAlignisnull.
-
withVerticalAlignment
A convenience method to avoid peeking into this builder like so:
This sets the vertical alignment of the icon and text and also binds the provided property to the underlying component.UI.button("Clickable!") .peek( button -> { property.onSetItem(v->button.setVerticalAlignment(v.forSwing())); button.setVerticalAlignment(property.get().forSwing()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to send the property value to this view component.- Parameters:
verticalAlign- The vertical alignment property which should be bound to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifverticalAlignisnull.
-
withHorizontalTextAlignment
A convenience method to avoid peeking into this builder like so:
This sets the horizontal position of the text relative to the icon.UI.button("Clickable!") .peek( button -> button.setHorizontalTextPosition(...) );- Parameters:
horizontalAlign- The horizontal text alignment relative to the icon which should be applied to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifhorizontalAlignisnull.
-
withHorizontalTextAlignment
A convenience method to avoid peeking into this builder like so:
This sets the horizontal position of the text relative to the icon and also binds the provided property to the underlying component.UI.button("Clickable!") .peek( button -> { property.onSetItem(v->button.setHorizontalTextPosition(v.forSwing())); button.setHorizontalTextPosition(property.get().forSwing()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to send the property value to this view component.- Parameters:
horizontalAlign- The horizontal text alignment property relative to the icon which should be bound to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifhorizontalAlignisnull.
-
withVerticalTextAlignment
A convenience method to avoid peeking into this builder like so:
This sets the vertical position of the text relative to the icon.UI.button("Clickable!") .peek( button -> button.setVerticalTextPosition(...) );- Parameters:
verticalAlign- The vertical text alignment relative to the icon which should be applied to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifverticalAlignisnull.
-
withVerticalTextAlignment
A convenience method to avoid peeking into this builder like so:
This sets the vertical position of the text relative to the icon and also binds the provided property to the underlying component.UI.button("Clickable!") .peek( button -> { property.onSetItem(v->button.setVerticalTextPosition(v.forSwing())); button.setVerticalTextPosition(property.get().forSwing()); });
Hint: UsemyProperty.fire(From.VIEW_MODEL)in your view model to send the property value to this view component.- Parameters:
verticalAlign- The vertical text alignment property relative to the icon which should be bound to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException- ifverticalAlignisnull.
-
withButtonGroup
Use this to attach this button type to a button group.- Parameters:
group- The button group to which this button should be attached.- Returns:
- This very builder to allow for method chaining.
-
withMargin
Use this to set the margin of the wrapped button type.- Parameters:
insets- The margin of the button.- Returns:
- This very builder to allow for method chaining.
-
withMargin
Use this to set the margin of the wrapped button type.- Parameters:
top- The top margin of the button.left- The left margin of the button.bottom- The bottom margin of the button.right- The right margin of the button.- Returns:
- This very builder to allow for method chaining.
-