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 Summary
Modifier and TypeMethodDescriptionprotected UIForLabel
<L> _newBuilderWithState
(swingtree.BuilderState<L> newState) An internal wither method which creates a new builder instance with the providedBuilderState
stored inside it.protected swingtree.BuilderState
<L> _state()
Returns the state of the builder, which is a container for the wrapped component as well as it's type and currentEventProcessor
.final UIForLabel
<L> isBoldIf
(boolean isBold) Makes the wrappedJLabel
font bold if the provided flag is true, and plain if the flag is false.final UIForLabel
<L> When the flag wrapped by the provided property changes, then the font of this label will switch between being bold and plain.makeBold()
Makes the wrappedJLabel
font bold (!plain).makeLinkTo
(String href) Use this to make the underlyingJLabel
into a clickable link.makeLinkTo
(sprouts.Val<String> href) Use this to make the underlyingJLabel
into a clickable link based on the string provided property defining the link address.Makes the wrappedJLabel
font plain (!bold).final UIForLabel
<L> Makes the wrappedJLabel
font bold if it is plain and plain if it is bold...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).withAlignment
(UI.Alignment alignment) Use this to set the horizontal and vertical alignment of the label's content (icon and text).final UIForLabel
<L> Use this to set the font of the wrappedJLabel
.final UIForLabel
<L> Use this to dynamically set the font of the wrappedJLabel
through the provided view model property.withFontSize
(int size) Use this to set the size of the font of the wrappedJLabel
.withFontSize
(sprouts.Val<Integer> size) Use this to dynamically set the size of the font of the wrappedJLabel
through the provided view model property.withHorizontalAlignment
(sprouts.Val<UI.HorizontalAlignment> horizontalAlign) This binds to a property defining the horizontal alignment of the label's content (icon and text).withHorizontalAlignment
(UI.HorizontalAlignment horizontalAlign) A convenience method to avoid peeking into this builder like so: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.withHorizontalTextPosition
(UI.HorizontalAlignment horizontalAlign) Use this to set the horizontal position of the label's text, relative to its image.Use this to set the icon for the wrappedJLabel
.withIcon
(sprouts.Val<IconDeclaration> icon) Use this to dynamically set the icon property for the wrappedJLabel
.withIcon
(IconDeclaration icon) Use this to set the icon for the wrappedJLabel
based on the providedIconDeclaration
.final UIForLabel
<L> Defines the single line of text this component will display.final UIForLabel
<L> Dynamically defines a single line of text displayed on this label.withTextPosition
(UI.Alignment alignment) Use this to set the horizontal and vertical position of the label's text, relative to its image.withVerticalAlignment
(sprouts.Val<UI.VerticalAlignment> verticalAlign) This binds to a property defining the vertical alignment of the label's content (icon and text).withVerticalAlignment
(UI.VerticalAlignment verticalAlign) Use this to set the vertical alignment of the label's content (icon and text).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.withVerticalTextPosition
(UI.VerticalAlignment verticalAlign) Use this to set the horizontal position of the label's text, relative to its image.Methods inherited from class swingtree.UIForAnySwing
_addComponentTo, _addViewableProps, _addViewableProps, _isUndefinedColor, _isUndefinedFont, _setBackground, _setEnabled, _setMinHeight, _setMinWidth, _setPrefWidth, add, add, add, add, add, add, add, add, add, add, addAll, addAll, addAll, addAll, addAll, addAll, doUpdates, group, group, id, id, isEnabledIf, isEnabledIf, isEnabledIf, isEnabledIfNot, isEnabledIfNot, isEnabledIfNot, isFocusableIf, isFocusableIf, isFocusableIf, isFocusableIfNot, isFocusableIfNot, isFocusableIfNot, isValidIf, isVisibleIf, isVisibleIf, isVisibleIf, isVisibleIfNot, isVisibleIfNot, isVisibleIfNot, makeFocused, makeNonOpaque, makeOpaque, on, on, onCharTyped, onFocusGain, onFocusLoss, onHidden, onKeyPress, onKeyRelease, onKeyTyped, onMouseClick, onMouseDrag, onMouseEnter, onMouseEnter, onMouseEnterGreedy, onMouseExit, onMouseExit, onMouseExitGreedy, onMouseMove, onMousePress, onMouseRelease, onMouseWheelDown, onMouseWheelMove, onMouseWheelUp, onMoved, onPressed, onRelease, onResize, onShown, onTyped, onTyped, onView, withBackground, withBackground, withBackgroundColor, withBackgroundIf, withBackgroundIf, withBackgroundIf, withBackgroundIf, withBorder, withBorder, withBorderTitled, withBorderTitled, withBoxLayout, withCompoundBorder, withCompoundBorderTitled, withCursor, withCursor, withCursorIf, withCursorIf, withDragAway, withDropSite, withEmptyBorder, withEmptyBorder, withEmptyBorder, withEmptyBorder, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withFlowLayout, withFlowLayout, withFlowLayout, withForeground, withForeground, withForegroundColor, withForegroundIf, withForegroundIf, withForegroundIf, withForegroundIf, withGridBagLayout, withGridLayout, withGridLayout, withGridLayout, withHeight, withHeight, withHeightExactly, withHeightExactly, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLineBorder, withLineBorder, withLineBorder, withLineBorderTitled, withLineBorderTitled, withLineBorderTitled, withLineBorderTitled, withMatteBorder, withMatteBorder, withMatteBorder, withMatteBorderTitled, withMatteBorderTitled, withMatteBorderTitled, withMaxHeight, withMaxHeight, withMaxSize, withMaxSize, withMaxSize, withMaxSize, withMaxSize, withMaxWidth, withMaxWidth, withMinHeight, withMinHeight, withMinSize, withMinSize, withMinSize, withMinSize, withMinSize, withMinWidth, withMinWidth, withPrefHeight, withPrefHeight, withPrefSize, withPrefSize, withPrefSize, withPrefSize, withPrefSize, withPrefWidth, withPrefWidth, withProperty, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withSize, withSize, withSize, withSize, withSizeExactly, withSizeExactly, withSizeExactly, withSizeExactly, withStyle, withTooltip, withTooltip, withTransitionalStyle, withTransitoryStyle, withWidth, withWidth, withWidthExactly, withWidthExactly
Methods inherited from class swingtree.UIForAnything
_addBuildersTo, _addBuilderTo, _addComponentsTo, _disposeState, _onShow, _onShow, _runInApp, _runInApp, _runInUI, _this, _with, _withOnShow, _withOnShow, add, add, add, add, apply, applyIf, applyIfPresent, component, equals, get, getComponent, getType, hashCode, peek, toString
-
Method Details
-
_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 currentEventProcessor
.- Specified by:
_state
in classUIForAnything<UIForLabel<L extends JLabel>,
L extends JLabel, JComponent> - Returns:
- The state of the builder.
-
_newBuilderWithState
Description copied from class:UIForAnything
An internal wither method which creates a new builder instance with the providedBuilderState
stored inside it.- Specified by:
_newBuilderWithState
in classUIForAnything<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
Makes the wrappedJLabel
font bold (!plain).- Returns:
- This very builder to allow for method chaining.
-
makeLinkTo
Use this to make the underlyingJLabel
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
- ifhref
isnull
.
-
makeLinkTo
Use this to make the underlyingJLabel
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
- ifhref
isnull
.
-
makePlain
Makes the wrappedJLabel
font plain (!bold).- Returns:
- This very builder to allow for method chaining.
-
toggleBold
Makes the wrappedJLabel
font bold if it is plain and plain if it is bold...- Returns:
- This very builder to allow for method chaining.
-
isBoldIf
Makes the wrappedJLabel
font bold if the provided flag is true, and plain if the flag is false. SeemakeBold()
andmakePlain()
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
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
- ifisBold
isnull
.
-
withText
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
- iftext
isnull
.
-
withText
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
- iftext
isnull
.
-
withHorizontalAlignment
A convenience method to avoid peeking into this builder like so:
This sets the horizontal alignment of the label's content (icon and text).UI.label("Something") .peek( label -> label.setHorizontalAlignment(...) );
- Parameters:
horizontalAlign
- The horizontal alignment which should be applied to the underlying component.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException
- ifhorizontalAlign
isnull
.
-
withHorizontalAlignment
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
- ifhorizontalAlign
isnull
.
-
withVerticalAlignment
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
- ifverticalAlign
isnull
.
-
withVerticalAlignment
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
- ifverticalAlign
isnull
.
-
withAlignment
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
- ifalignment
isnull
.
-
withAlignment
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
- ifalignment
isnull
.
-
withHorizontalTextPosition
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
- ifhorizontalAlign
isnull
.
-
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
- ifhorizontalAlign
isnull
.
-
withVerticalTextPosition
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
- ifverticalAlign
isnull
.
-
withVerticalTextPosition
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
- ifverticalAlign
isnull
.
-
withTextPosition
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
- ifalignment
isnull
.
-
withIcon
Use this to set the icon for the wrappedJLabel
. This is in essence a convenience method to avoid peeking into this builder like so:UI.label("Something") .peek( label -> label.setIcon(...) );
- Parameters:
icon
- TheIcon
which should be displayed on the label.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Use this to set the icon for the wrappedJLabel
based on the providedIconDeclaration
.An
IconDeclaration
should be preferred over theIcon
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
- TheIconDeclaration
which should be displayed on the label.- Returns:
- This very builder to allow for method chaining.
-
withIcon
Use this to dynamically set the icon property for the wrappedJLabel
. 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
orImageIcon
classes directly, instead you must use implementations of theIconDeclaration
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
- TheIcon
property which should be displayed on the label.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException
- ificon
isnull
.
-
withFontSize
Use this to set the size of the font of the wrappedJLabel
.- Parameters:
size
- The size of the font which should be displayed on the label.- Returns:
- This very builder to allow for method chaining.
-
withFontSize
Use this to dynamically set the size of the font of the wrappedJLabel
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
- ifsize
isnull
.
-
withFont
Use this to set the font of the wrappedJLabel
.- 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
- iffont
isnull
.
-
withFont
Use this to dynamically set the font of the wrappedJLabel
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
- iffont
isnull
.IllegalArgumentException
- iffont
is a property which can wrapnull
.
-