Package swingtree

Class UIForLabel<L extends JLabel>


public final class UIForLabel<L extends JLabel> extends UIForAnySwing<UIForLabel<L>,L>
A SwingTree builder node designed for configuring JLabel instances.

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.

  • Method Details

    • _state

      protected swingtree.BuilderState<L> _state()
      Description copied from class: UIForAnything
      Returns the state of the builder, which is a container for the wrapped component as well as it's type and current EventProcessor.
      Specified by:
      _state in class UIForAnything<UIForLabel<L extends JLabel>,L extends JLabel,JComponent>
      Returns:
      The state of the builder.
    • _newBuilderWithState

      protected UIForLabel<L> _newBuilderWithState(swingtree.BuilderState<L> newState)
      Description copied from class: UIForAnything
      An internal wither method which creates a new builder instance with the provided BuilderState stored inside it.
      Specified by:
      _newBuilderWithState in class UIForAnything<UIForLabel<L extends JLabel>,L extends JLabel,JComponent>
      Parameters:
      newState - The new state which should be stored inside the new builder instance.
      Returns:
      A new builder instance with the provided state stored inside it.
    • makeBold

      public UIForLabel<L> makeBold()
      Makes the wrapped JLabel font bold (!plain).
      Returns:
      This very builder to allow for method chaining.
    • makeLinkTo

      public UIForLabel<L> makeLinkTo(String href)
      Use this to make the underlying JLabel into a clickable link.
      Parameters:
      href - A string containing a valid URL used as link hyper reference.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if href is null.
    • makeLinkTo

      public UIForLabel<L> makeLinkTo(sprouts.Val<String> href)
      Use this to make the underlying JLabel into a clickable link based on the string provided property defining the link address. When the link wrapped by the provided property changes, then a click on the label will lead to the wrapped link.
      Parameters:
      href - A string property containing a valid URL used as link hyper reference.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if href is null.
    • makePlain

      public UIForLabel<L> makePlain()
      Makes the wrapped JLabel font plain (!bold).
      Returns:
      This very builder to allow for method chaining.
    • toggleBold

      public final UIForLabel<L> toggleBold()
      Makes the wrapped JLabel font bold if it is plain and plain if it is bold...
      Returns:
      This very builder to allow for method chaining.
    • isBoldIf

      public final UIForLabel<L> isBoldIf(boolean isBold)
      Makes the wrapped JLabel font bold if the provided flag is true, and plain if the flag is false. See makeBold() and makePlain() for more information.
      Parameters:
      isBold - The flag determining if the font of this label should be bold or plain.
      Returns:
      This very builder to allow for method chaining.
    • isBoldIf

      public final UIForLabel<L> isBoldIf(sprouts.Val<Boolean> isBold)
      When the flag wrapped by the provided property changes, then the font of this label will switch between being bold and plain.
      Parameters:
      isBold - The property which should be bound to the boldness of this label.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if isBold is null.
    • withText

      public final UIForLabel<L> withText(String text)
      Defines the single line of text this component will display. If the value of text is null or empty string, nothing is displayed.

      The default value of this property is null.

      Parameters:
      text - The new text to be set for the wrapped label.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if text is null.
    • withText

      public final UIForLabel<L> withText(sprouts.Val<String> text)
      Dynamically defines a single line of text displayed on this label. If the value of text is null or an empty string, nothing is displayed. When the text wrapped by the provided property changes, then so does the text displayed on this label change.
      Parameters:
      text - The text property to be bound to the wrapped label.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if text is null.
    • withHorizontalAlignment

      public UIForLabel<L> withHorizontalAlignment(UI.HorizontalAlignment horizontalAlign)
      A convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
           .peek( label -> label.setHorizontalAlignment(...) );
        
      This sets the horizontal alignment of the label's content (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 UIForLabel<L> withHorizontalAlignment(sprouts.Val<UI.HorizontalAlignment> horizontalAlign)
      This binds to a property defining the horizontal alignment of the label's content (icon and text). When the alignment enum wrapped by the provided property changes, then so does the alignment of this label.
      Parameters:
      horizontalAlign - The horizontal alignment property which should be applied to the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if horizontalAlign is null.
    • withVerticalAlignment

      public UIForLabel<L> withVerticalAlignment(UI.VerticalAlignment verticalAlign)
      Use this to set the vertical alignment of the label's content (icon and text). This is a convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
           .peek( label -> label.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 - if verticalAlign is null.
    • withVerticalAlignment

      public UIForLabel<L> withVerticalAlignment(sprouts.Val<UI.VerticalAlignment> verticalAlign)
      This binds to a property defining the vertical alignment of the label's content (icon and text). When the alignment enum wrapped by the provided property changes, then so does the alignment of this label.
      Parameters:
      verticalAlign - The vertical alignment property which should be applied to the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if verticalAlign is null.
    • withAlignment

      public UIForLabel<L> withAlignment(UI.Alignment alignment)
      Use this to set the horizontal and vertical alignment of the label's content (icon and text). This is a convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
           .peek( label -> label.setHorizontalAlignment(...); label.setVerticalAlignment(...) );
        
      Parameters:
      alignment - The alignment which should be applied to the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if alignment is null.
    • withAlignment

      public UIForLabel<L> withAlignment(sprouts.Val<UI.Alignment> alignment)
      This binds to a property defining the horizontal and vertical alignment of the label's content (icon and text). When the alignment enum wrapped by the provided property changes, then so does the alignment of this label.
      Parameters:
      alignment - The alignment property which should be applied to the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if alignment is null.
    • withHorizontalTextPosition

      public UIForLabel<L> withHorizontalTextPosition(UI.HorizontalAlignment horizontalAlign)
      Use this to set the horizontal position of the label's text, relative to its image. A convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
               .peek( label -> label.setHorizontalTextPosition(...) );
        
      Parameters:
      horizontalAlign - The horizontal alignment which should be applied to the text of the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if horizontalAlign is null.
    • withHorizontalTextPosition

      public UIForLabel<L> withHorizontalTextPosition(sprouts.Val<UI.HorizontalAlignment> horizontalAlign)
      Use this to bind to a property defining the horizontal position of the label's text, relative to its image. When the alignment enum wrapped by the provided property changes, then so does the alignment of this label.
      Parameters:
      horizontalAlign - The horizontal alignment property which should be applied to the text of the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if horizontalAlign is null.
    • withVerticalTextPosition

      public UIForLabel<L> withVerticalTextPosition(UI.VerticalAlignment verticalAlign)
      Use this to set the horizontal position of the label's text, relative to its image.
      This is a convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
           .peek( label -> label.setVerticalTextPosition(...) );
        
      Parameters:
      verticalAlign - The vertical alignment which should be applied to the text of the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if verticalAlign is null.
    • withVerticalTextPosition

      public UIForLabel<L> withVerticalTextPosition(sprouts.Val<UI.VerticalAlignment> verticalAlign)
      Use this to bind to a property defining the vertical position of the label's text, relative to its image. When the alignment enum wrapped by the provided property changes, then so does the alignment of this label.
      Parameters:
      verticalAlign - The vertical alignment property which should be applied to the text of the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if verticalAlign is null.
    • withTextPosition

      public UIForLabel<L> withTextPosition(UI.Alignment alignment)
      Use this to set the horizontal and vertical position of the label's text, relative to its image. This is a convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
               .peek( label -> label.setHorizontalTextPosition(...); label.setVerticalTextPosition(...) );
        
      Parameters:
      alignment - The alignment which should be applied to the text of the underlying component.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if alignment is null.
    • withIcon

      public UIForLabel<L> withIcon(Icon icon)
      Use this to set the icon for the wrapped JLabel. This is in essence a convenience method to avoid peeking into this builder like so:
      
           UI.label("Something")
               .peek( label -> label.setIcon(...) );
        
      Parameters:
      icon - The Icon which should be displayed on the label.
      Returns:
      This very builder to allow for method chaining.
    • withIcon

      public UIForLabel<L> withIcon(IconDeclaration icon)
      Use this to set the icon for the wrapped JLabel based on the provided IconDeclaration.

      An IconDeclaration should be preferred over the Icon class as part of a view model, because it 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.

      Parameters:
      icon - The IconDeclaration which should be displayed on the label.
      Returns:
      This very builder to allow for method chaining.
    • withIcon

      public UIForLabel<L> withIcon(sprouts.Val<IconDeclaration> icon)
      Use this to dynamically set the icon property for the wrapped JLabel. When the icon wrapped by the provided property changes, then so does the icon of this label.

      But note that you may not 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 in case of unit tests for you 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 label.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if icon is null.
    • withFontSize

      public UIForLabel<L> withFontSize(int size)
      Use this to set the size of the font of the wrapped JLabel.
      Parameters:
      size - The size of the font which should be displayed on the label.
      Returns:
      This very builder to allow for method chaining.
    • withFontSize

      public UIForLabel<L> withFontSize(sprouts.Val<Integer> size)
      Use this to dynamically set the size of the font of the wrapped JLabel through the provided view model property. When the integer wrapped by the provided property changes, then so does the font size of this label.
      Parameters:
      size - The size property of the font which should be displayed on the label.
      Returns:
      This very builder to allow for method chaining.
      Throws:
      IllegalArgumentException - if size is null.
    • withFont

      public final UIForLabel<L> withFont(Font font)
      Use this to set the font of the wrapped JLabel.
      Parameters:
      font - The font of the text which should be displayed on the label.
      Returns:
      This builder instance, to allow for method chaining.
      Throws:
      IllegalArgumentException - if font is null.
    • withFont

      public final UIForLabel<L> withFont(sprouts.Val<Font> font)
      Use this to dynamically set the font of the wrapped JLabel through the provided view model property. When the font wrapped by the provided property changes, then so does the font of this label.
      Parameters:
      font - The font property of the text which should be displayed on the label.
      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.