Package swingtree

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

public abstract class UIForAnyButton<I,B extends AbstractButton> extends UIForAnySwing<I,B>
The following is a more specialized type of builder node based on the 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 Details

    • UIForAnyButton

      public UIForAnyButton()
  • Method Details

    • withText

      public final I withText(String text)
      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

      public final I withText(sprouts.Val<String> text)
      Binds the provided Val property to the wrapped button type and sets the text of the button to the value of the property. Hint: Use myProperty.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 - if text is null.
    • withIcon

      public I withIcon(Icon icon)
      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:
      
           UI.button("Something")
           .peek( button -> button.setIcon(...) );
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also see withIcon(IconDeclaration), which is the recommended way of setting icons on buttons!
      Parameters:
      icon - The Icon which should be displayed on the button.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if icon is null.
    • withIcon

      public I withIcon(IconDeclaration icon)
      Use this to specify the icon for the wrapped button type. The icon is determined based on the provided IconDeclaration instance 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:
      
           UI.button("Click me!")
           .peek( button -> icon.find().ifPresent(button::setIcon) );
        
      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 current UI.scale() factor (see ScalableImageIcon) 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

      public I withIcon(sprouts.Val<IconDeclaration> icon)
      Use this to dynamically set the icon property for the wrapped button type. When the IconDeclaration wrapped 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:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setIcon)
           ));
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed on the button.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if icon is null.
    • withIcon

      public I withIcon(int width, int height, Icon icon)
      Takes the provided Icon and scales it to the provided width and height before displaying it on the wrapped button type.
      Also see withIcon(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which should be scaled and displayed on the button.
      Returns:
      This very builder to allow for method chaining.
    • withIcon

      public I withIcon(int width, int height, IconDeclaration icon)
      Takes the provided IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which should be scaled and displayed on the button.
      Returns:
      This very builder to allow for method chaining.
    • withIcon

      public I withIcon(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the provided IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The IconDeclaration, whose referenced icon will be scaled and displayed on the button.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled relative to the button.
      Returns:
      This very builder to allow for method chaining.
    • withIcon

      public I withIcon(Icon icon, UI.FitComponent fitComponent)
      Sets the Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is also used as the "pressed" and "disabled" icon if there is no explicitly set pressed icon.
      Please also see withIcon(IconDeclaration, UI.FitComponent), which is the recommended way of setting icons on buttons!
      Parameters:
      icon - The Icon which should be displayed on the button. Ideally, this should be an SvgIcon to ensure that UI.FitComponent can be applied properly.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled to fit the component.
      Returns:
      This very builder to allow for method chaining.
    • withIcon

      public I withIcon(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.
      Parameters:
      icon - The IconDeclaration which should be displayed on the button.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
    • withIconOnPress

      public I withIconOnPress(Icon icon)
      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:
      
           UI.button("Something")
           .peek( button -> button.setPressedIcon(...) );
        
      Please also see withIconOnPress(IconDeclaration), which is the recommended way of setting icons on buttons!
      Parameters:
      icon - The Icon which should be displayed when the button is pressed.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnPress

      public I withIconOnPress(int width, int height, Icon icon)
      Takes the provided Icon and scales it to the provided width and height before displaying it on the wrapped button type when the user presses the button type.
      Also see withIconOnPress(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which should be scaled and then displayed when the button is being pressed.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnPress

      public I withIconOnPress(int width, int height, IconDeclaration icon)
      Takes the supplied IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which should be scaled and then displayed when the button is being pressed.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnPress

      public I withIconOnPress(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the provided IconDeclaration and 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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The Icon which should be scaled and then displayed when the button is being pressed.
      fitComponent - The UI.FitComponent which 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 are null!
    • withIconOnPress

      public I withIconOnPress(Icon icon, UI.FitComponent fitComponent)
      Sets the pressed Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the user presses the button type.
      Please also see withIconOnPress(IconDeclaration, UI.FitComponent), which is the recommended way of setting pressed icons on buttons!
      Parameters:
      icon - The SvgIcon which should be displayed when the button is being pressed.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnPress

      public I withIconOnPress(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the pressed Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed temporarily when the user presses and holds the button.
      Parameters:
      icon - The IconDeclaration which should be displayed when the button is being pressed.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnPress

      public I withIconOnPress(IconDeclaration icon)
      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 supplied IconDeclaration instance 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 - if icon is null!
    • withIconOnPress

      public I 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. When the icon wrapped by the supplied Val property 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:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setPressedIcon)
           ));
        
      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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed when the button is being pressed.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnHover

      public I withIconOnHover(Icon icon)
      Use this to set the "hovered" icon for the wrapped button type, which translates to AbstractButton.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:
      
           UI.button("Something")
           .peek( button -> button.setRolloverIcon(...) );
        
      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 the UI.scale() factor. Please also see withIconOnHover(IconDeclaration), which is the recommended way of setting icons on buttons!
      Parameters:
      icon - The Icon which should be displayed when the cursor hovers over the button.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnHover

      public I withIconOnHover(int width, int height, Icon icon)
      Takes the provided Icon and 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 see withIconOnHover(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which should be scaled and then displayed when the button is being hovered over.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnHover

      public I withIconOnHover(int width, int height, IconDeclaration icon)
      Takes the supplied IconDeclaration and 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:

      
           UI.button("Click me!")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.withSize(width,height)
                       .find()
                       .ifPresent(button::setRolloverIcon)
           ));
        
      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 a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which 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 - if icon is null!
    • withIconOnHover

      public I withIconOnHover(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the supplied IconDeclaration and scales the corresponding icon it to the desired width and height after which it uses the UI.FitComponent layout policy enum constant to display it on the wrapped button type whenever the user hovers their cursor over the button...
      Note that the width and height properties only serve as reference values as the UI.FitComponent is 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 a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The Icon which should be scaled and then displayed when the button is being hovered over.
      fitComponent - The UI.FitComponent which 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 are null!
    • withIconOnHover

      public I withIconOnHover(Icon icon, UI.FitComponent fitComponent)
      Sets the hover Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the user hovers their cursor over the button type.
      Please also see withIconOnHover(IconDeclaration, UI.FitComponent), which is the recommended way of setting hover icons on buttons!
      Parameters:
      icon - The SvgIcon which should be displayed when the button is being hovered over.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnHover

      public I withIconOnHover(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the hover Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed temporarily when the user hovers their mouse cursor over the button area.
      Parameters:
      icon - The IconDeclaration which should be displayed when the button is being hovered over.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnHover

      public I withIconOnHover(IconDeclaration icon)
      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 supplied IconDeclaration instance 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 - if icon is null!
    • withIconOnHover

      public I 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. When the icon wrapped by the supplied Val property changes, then so does the "hover icon" of this button. Or more specifically, the AbstractButton.getRolloverIcon() property of the underlying component.

      For most scenarios, this is a convenience method equivalent to peeking into this builder like so:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setRolloverIcon)
           ));
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed when the button is being hovered over.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(Icon icon)
      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:
      
           UI.button("Something")
           .peek( button -> button.setRolloverSelectedIcon(...) );
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also see withIconOnHoverAndSelected(IconDeclaration), which is the recommended way of setting rollover and selected icons on buttons!
      Parameters:
      icon - The Icon which should be displayed when the button is both rolled over and selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(int width, int height, Icon icon)
      Takes the provided Icon and 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 see withIconOnHoverAndSelected(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which 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 - if icon is null!
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(int width, int height, IconDeclaration icon)
      Takes the supplied IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which 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 - if icon is null!
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the provided IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The Icon which should be scaled and then displayed when the button is both rolled over and selected.
      fitComponent - The UI.FitComponent which 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 are null!
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(Icon icon, UI.FitComponent fitComponent)
      Sets the rollover and selected Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the button is both rolled over and selected.
      Please also see withIconOnHoverAndSelected(IconDeclaration, UI.FitComponent), which is the recommended way of setting rollover and selected icons on buttons!
      Parameters:
      icon - The SvgIcon which should be displayed when the button is both rolled over and selected.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the rollover and selected Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.
      Parameters:
      icon - The IconDeclaration which should be displayed when the button is both rolled over and selected.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnHoverAndSelected

      public I withIconOnHoverAndSelected(IconDeclaration icon)
      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 supplied IconDeclaration instance which serves as a resource path to the icon actual.
      This method will try to load and install the icon as a scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 - if icon is null!
    • withIconOnHoverAndSelected

      public I 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. When the icon wrapped by the supplied Val property 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:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setRolloverSelectedIcon)
           ));
        
      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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed when the button is both rolled over and selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnSelected

      public I withIconOnSelected(Icon icon)
      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:
      
           UI.button("Something")
           .peek( button -> button.setSelectedIcon(...) );
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also see withIconOnSelected(IconDeclaration), which is the recommended way of setting selected icons on buttons!
      Parameters:
      icon - The Icon which should be displayed when the button is selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnSelected

      public I withIconOnSelected(int width, int height, Icon icon)
      Takes the provided Icon and scales it to the provided width and height before displaying it on the wrapped button type when the button is selected.
      Also see withIconOnSelected(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which should be scaled and then displayed when the button is selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnSelected

      public I withIconOnSelected(int width, int height, IconDeclaration icon)
      Takes the supplied IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which should be scaled and then displayed when the button is selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnSelected

      public I withIconOnSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the provided IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The Icon which should be scaled and then displayed when the button is selected.
      fitComponent - The UI.FitComponent which 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 are null!
    • withIconOnSelected

      public I withIconOnSelected(Icon icon, UI.FitComponent fitComponent)
      Sets the selected Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the button is selected.
      Please also see withIconOnSelected(IconDeclaration, UI.FitComponent), which is the recommended way of setting selected icons on buttons!
      Parameters:
      icon - The SvgIcon which should be displayed when the button is selected.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnSelected

      public I withIconOnSelected(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the selected Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the button is selected.
      This method will try to load and install the icon as a scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.
      Parameters:
      icon - The IconDeclaration which should be displayed when the button is selected.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnSelected

      public I withIconOnSelected(IconDeclaration icon)
      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 supplied IconDeclaration instance which serves as a resource path to the icon actual.
      This method will try to load and install the icon as a scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 - if icon is null!
    • withIconOnSelected

      public I 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. When the icon wrapped by the supplied Val property 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:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setSelectedIcon)
           ));
        
      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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed when the button is selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnDisabled

      public I withIconOnDisabled(Icon icon)
      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:
      
           UI.button("Something")
           .peek( button -> button.setDisabledIcon(...) );
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also see withIconOnDisabled(IconDeclaration), which is the recommended way of setting disabled icons on buttons!
      Parameters:
      icon - The Icon which should be displayed when the button is disabled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnDisabled

      public I withIconOnDisabled(int width, int height, Icon icon)
      Takes the provided Icon and scales it to the provided width and height before displaying it on the wrapped button type when the button is disabled.
      Also see withIconOnDisabled(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which should be scaled and then displayed when the button is disabled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnDisabled

      public I withIconOnDisabled(int width, int height, IconDeclaration icon)
      Takes the supplied IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which should be scaled and then displayed when the button is disabled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null!
    • withIconOnDisabled

      public I withIconOnDisabled(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the provided IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The Icon which should be scaled and then displayed when the button is disabled.
      fitComponent - The UI.FitComponent which 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 are null!
    • withIconOnDisabled

      public I withIconOnDisabled(Icon icon, UI.FitComponent fitComponent)
      Sets the disabled Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the button is disabled.
      Please also see withIconOnDisabled(IconDeclaration, UI.FitComponent), which is the recommended way of setting disabled icons on buttons!
      Parameters:
      icon - The SvgIcon which should be displayed when the button is disabled.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnDisabled

      public I withIconOnDisabled(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the disabled Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the button is disabled.
      This method will try to load and install the icon as a scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.
      Parameters:
      icon - The IconDeclaration which should be displayed when the button is disabled.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnDisabled

      public I withIconOnDisabled(IconDeclaration icon)
      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 supplied IconDeclaration instance which serves as a resource path to the icon actual.
      This method will try to load and install the icon as a scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 - if icon is null!
    • withIconOnDisabled

      public I 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. When the icon wrapped by the supplied Val property 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:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setDisabledIcon)
           ));
        
      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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed when the button is disabled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(Icon icon)
      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:
      
           UI.button("Something")
           .peek( button -> button.setDisabledSelectedIcon(...) );
        
      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 current UI.scale() factor (see ScalableImageIcon) so that the icon is upscaled proportionally in high-dpi environments. Please also see withIconOnDisabledAndSelected(IconDeclaration), which is the recommended way of setting disabled and selected icons on buttons!
      Parameters:
      icon - The Icon which should be displayed when the button is both disabled and selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(int width, int height, Icon icon)
      Takes the provided Icon and 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 see withIconOnDisabledAndSelected(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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The Icon which 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 - if icon is null!
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(int width, int height, IconDeclaration icon)
      Takes the supplied IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale().
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale().
      icon - The IconDeclaration which 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 - if icon is null!
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(int width, int height, IconDeclaration icon, UI.FitComponent fitComponent)
      Takes the provided IconDeclaration and 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 by UI.scale() and UI.FitComponent.
      height - The desired height of the icon in "developer pixels", the actual width may be influenced by UI.scale() and UI.FitComponent.
      icon - The Icon which should be scaled and then displayed when the button is both disabled and selected.
      fitComponent - The UI.FitComponent which 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 are null!
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(Icon icon, UI.FitComponent fitComponent)
      Sets the disabled and selected Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. This icon is only displayed when the button is both disabled and selected.
      Please also see withIconOnDisabledAndSelected(IconDeclaration, UI.FitComponent), which is the recommended way of setting disabled and selected icons on buttons!
      Parameters:
      icon - The SvgIcon which should be displayed when the button is both disabled and selected.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(IconDeclaration icon, UI.FitComponent fitComponent)
      Sets the disabled and selected Icon property of the wrapped button type and scales it according to the provided UI.FitComponent policy. 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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.
      Parameters:
      icon - The IconDeclaration which should be displayed when the button is both disabled and selected.
      fitComponent - The UI.FitComponent which determines how the icon should be scaled.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if any of the supplied arguments are null!
    • withIconOnDisabledAndSelected

      public I withIconOnDisabledAndSelected(IconDeclaration icon)
      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 supplied IconDeclaration instance which serves as a resource path to the icon actual.
      This method will try to load and install the icon as a scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.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 - if icon is null!
    • withIconOnDisabledAndSelected

      public I 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. When the icon wrapped by the supplied Val property 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:

      
           UI.button("Something")
           .peek( button -> iconProperty.onChange(From.ALL,
                icon -> icon.find().ifPresent(button::setDisabledSelectedIcon)
           ));
        
      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 scalable ImageIcon, which means that in case of the referenced icon being an SVG file, the icon will be loaded as a smoothly scalable SvgIcon, if it is a png or jpeg file however, then this method will represent it as a ScalableImageIcon, which dynamically scales the underlying image according to the UI.scale() so that it has a proportionally correct size in high-dpi environments.

      But note that here you cannot use the Icon or ImageIcon classes directly, instead you must use implementations of the IconDeclaration interface, 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 IconDeclaration interface, 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 - The Icon property which should be displayed when the button is both disabled and selected.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      NullPointerException - if icon is null.
    • withFontSize

      public I withFontSize(int size)
      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

      public I 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. 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 - if size is null.
    • withFont

      public final I withFont(Font font)
      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 - if font is null.
    • withFont

      public final I withFont(sprouts.Val<Font> font)
      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 - if font is null.
      IllegalArgumentException - if font is a property which can wrap null.
    • isSelectedIf

      public final I isSelectedIf(boolean isSelected)
      Use this to set the selection state of the wrapped button type.
      Parameters:
      isSelected - The selection state of the wrapped button type, which translates to AbstractButton.setSelected(boolean).
      Returns:
      This builder instance, to allow for method chaining.
    • isSelectedIf

      public final I isSelectedIf(sprouts.Val<Boolean> selected)
      Use this to bind to a Var instance which will be used to dynamically model the selection state of the wrapped AbstractButton type.
      Parameters:
      selected - The Var instance 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 - if selected is null.
    • isSelectedIfNot

      public final I isSelectedIfNot(sprouts.Val<Boolean> selected)
      Use this to bind to a Var instance which will be used to dynamically model the inverse selection state of the wrapped AbstractButton type.
      Parameters:
      selected - The Var instance 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 - if selected is null.
    • isSelectedIf

      public final I isSelectedIf(sprouts.Var<Boolean> selected)
      Use this to bind to a Var instance which will be used to dynamically model the selection state of the wrapped AbstractButton type.
      Parameters:
      selected - The Var instance 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 - if selected is null.
    • isSelectedIfNot

      public final I isSelectedIfNot(sprouts.Var<Boolean> selected)
      Use this to dynamically bind to a Var instance which will be used to dynamically model the inverse selection state of the wrapped AbstractButton type.
      Parameters:
      selected - The Var instance 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 - if selected is null.
    • isSelectedIf

      public final <T> I isSelectedIf(T state, sprouts.Val<T> selection)
      Use this to dynamically bind the selection flag of the button to a Val property 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 first state argument is equal to the value of the selection property, 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:
      
            // 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());
        
      As you can see, the radio button will be selected if the enum property is equal to the supplied enum value and deselected otherwise.

      Hint: Use myProperty.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 - The Val instance which will be used to dynamically model the selection state of the wrapped button type based on the equality of the state argument and the value of the property.
      Returns:
      The current builder type, to allow for further method chaining.
      Throws:
      IllegalArgumentException - if selected is null.
    • isSelectedIfNot

      public final <T> I isSelectedIfNot(T state, sprouts.Val<T> selection)
      This is the inverse of isSelectedIf(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: Use myProperty.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:
      
            // 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());
        
      As you can see, the radio button will be selected if the enum property is equal to the supplied enum value and deselected otherwise.
      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

      public final I isPressedIf(sprouts.Var<Boolean> var)
      Use this to dynamically bind to a Var instance which will be used to dynamically model the pressed state of the wrapped AbstractButton type.
      Parameters:
      var - The Var instance 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 - if var is null.
    • _onModelChange

      protected final void _onModelChange(B button, Consumer<ChangeEvent> action)
    • isBorderPaintedIf

      public I isBorderPaintedIf(boolean borderPainted)
      Sets the AbstractButton.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

      public I isBorderPaintedIf(sprouts.Val<Boolean> val)
      Binds the provided Val property to the AbstractButton.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

      public final I 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

      public final I onChange(sprouts.Action<ComponentDelegate<B,ItemEvent>> action)
      This method adds the provided ItemListener instance to the wrapped button component.

      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 - if action is null.
    • _onChange

      protected final void _onChange(B button, Consumer<ItemEvent> action)
    • onClick

      public I onClick(sprouts.Action<ComponentDelegate<B,ActionEvent>> action)
      This method enables a more readable way of adding ActionListener instances to button types. Additionally, to the other "onClick" method this method enables the involvement of the JComponent itself 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 - an Action instance which will receive an ComponentDelegate containing important context information.
      Returns:
      This very instance, which enables builder-style method chaining.
      Throws:
      IllegalArgumentException - if action is null.
    • _onClick

      protected final void _onClick(B button, Consumer<ActionEvent> action)
    • withHorizontalAlignment

      public final I withHorizontalAlignment(UI.HorizontalAlignment horizontalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
               .peek( button -> button.setHorizontalAlignment(...) );
        
      This sets the horizontal alignment of the icon and text.
      Parameters:
      horizontalAlign - The horizontal alignment which should be applied to the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if horizontalAlign is null.
    • withHorizontalAlignment

      public final I withHorizontalAlignment(sprouts.Val<UI.HorizontalAlignment> horizontalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
           .peek( button -> {
                property.onSetItem(v->button.setHorizontalAlignment(v.forSwing()));
                button.setHorizontalAlignment(property.get().forSwing());
           });
        
      This sets the horizontal alignment of the icon and text and also binds the provided property to the underlying component.
      Hint: Use myProperty.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 - if horizontalAlign is null.
    • withVerticalAlignment

      public final I withVerticalAlignment(UI.VerticalAlignment verticalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
               .peek( button -> button.setVerticalAlignment(...) );
        
      This sets the vertical alignment of the icon and text.
      Parameters:
      verticalAlign - The vertical alignment which should be applied to the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if verticalAlign is null.
    • withVerticalAlignment

      public final I withVerticalAlignment(sprouts.Val<UI.VerticalAlignment> verticalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
           .peek( button -> {
                property.onSetItem(v->button.setVerticalAlignment(v.forSwing()));
                button.setVerticalAlignment(property.get().forSwing());
           });
        
      This sets the vertical alignment of the icon and text and also binds the provided property to the underlying component.
      Hint: Use myProperty.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 - if verticalAlign is null.
    • withHorizontalTextAlignment

      public final I withHorizontalTextAlignment(UI.HorizontalAlignment horizontalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
               .peek( button -> button.setHorizontalTextPosition(...) );
        
      This sets the horizontal position of the text relative to the icon.
      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 - if horizontalAlign is null.
    • withHorizontalTextAlignment

      public final I withHorizontalTextAlignment(sprouts.Val<UI.HorizontalAlignment> horizontalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
           .peek( button -> {
                property.onSetItem(v->button.setHorizontalTextPosition(v.forSwing()));
                button.setHorizontalTextPosition(property.get().forSwing());
           });
        
      This sets the horizontal position of the text relative to the icon and also binds the provided property to the underlying component.
      Hint: Use myProperty.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 - if horizontalAlign is null.
    • withVerticalTextAlignment

      public final I withVerticalTextAlignment(UI.VerticalAlignment verticalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
               .peek( button -> button.setVerticalTextPosition(...) );
        
      This sets the vertical position of the text relative to the icon.
      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 - if verticalAlign is null.
    • withVerticalTextAlignment

      public final I withVerticalTextAlignment(sprouts.Val<UI.VerticalAlignment> verticalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.button("Clickable!")
           .peek( button -> {
                property.onSetItem(v->button.setVerticalTextPosition(v.forSwing()));
                button.setVerticalTextPosition(property.get().forSwing());
           });
        
      This sets the vertical position of the text relative to the icon and also binds the provided property to the underlying component.
      Hint: Use myProperty.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 - if verticalAlign is null.
    • withButtonGroup

      public final I withButtonGroup(ButtonGroup group)
      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

      public final I withMargin(Insets insets)
      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

      public final I withMargin(int top, int left, int bottom, int right)
      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.