Class UIForAnyTextComponent<I,C extends JTextComponent>
- Type Parameters:
I
- The type parameter for the instance type of this concrete class itself.C
- The type parameter for the text component type which is being built by this builder.
- Direct Known Subclasses:
UIForAnyEditorPane
,UIForFormattedTextField
,UIForPasswordField
,UIForTextArea
,UIForTextField
JTextComponent
instances
in a fluent and declarative way. It also allows for the binding of text properties to the text component
so that the text of the text component is dynamically updated whenever the value of the property changes
and conversely, the value of the property is dynamically updated whenever the text of the text component changes.
Please take a look at the living swing-tree documentation where you can browse a large collection of examples demonstrating how to use the API of this class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
_onTextChange
(C thisComponent, Consumer<DocumentEvent> action) protected final void
_setTextSilently
(C thisComponent, String text) final I
isEditableIf
(boolean isEditable) Use this to modify the components' modifiability.final I
onContentChange
(sprouts.Action<ComponentDelegate<JTextComponent, DocumentEvent>> action) Use this to register any change in the contents of the text component including both the displayed text and its attributes.final I
onTextChange
(sprouts.Action<ComponentDelegate<JTextComponent, DocumentEvent>> action) Use this to register if the text in this text component changes.final I
onTextInsert
(sprouts.Action<TextInsertDelegate> action) Allows you to register a user action listener which will be called whenever new text gets inserted into the underlying text component.final I
onTextRemove
(sprouts.Action<TextRemoveDelegate> action) Allows you to register a user action listener which will be called whenever parts (or all) of the text in the underlying text component gets removed.final I
onTextReplace
(sprouts.Action<TextReplaceDelegate> action) This method allows you to register a user action which will be called whenever the text in the underlying text component gets replaced.final I
Use this to set the font of the wrappedJTextComponent
.final I
Use this to dynamically set the font of the wrappedJTextComponent
through the provided view model property.final I
Sets the text of the wrapped
to the specified text.TextComponent
final I
Binds the text of the wrapped
to the specifiedTextComponent
Val
property instance so that the text of the wrapped text component is dynamically updated whenever the value of the property changes.final I
Binds the text of the wrapped
to the specifiedTextComponent
Val
property instance so that the text of the wrapped text component is dynamically updated whenever the value of the property changes.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, _newBuilderWithState, _onShow, _onShow, _runInApp, _runInApp, _runInUI, _state, _this, _with, _withOnShow, _withOnShow, add, add, add, add, apply, applyIf, applyIfPresent, component, equals, get, getComponent, getType, hashCode, peek, toString
-
Constructor Details
-
UIForAnyTextComponent
public UIForAnyTextComponent()
-
-
Method Details
-
withText
Sets the text of the wrapped
to the specified text. If the text isTextComponent
null
an exception is thrown. Please use an empty string instead of null! When text has been inserted, the resulting caret location is determined by the implementation of the caret class.Note that text is not a bound property, so no
PropertyChangeEvent
is fired when it changes. To listen for changes to the text, register action lambdas throughonTextChange(Action)
or useDocumentListener
directly.- Parameters:
text
- The new text to be set for the wrapped text component type.- Returns:
- This very builder to allow for method chaining.
-
withText
Binds the text of the wrapped
to the specifiedTextComponent
Val
property instance so that the text of the wrapped text component is dynamically updated whenever the value of the property changes.Note that the text of the wrapped text component is only updated if the new value is different from the old value. This is to avoid infinite feedback loops.
- Parameters:
text
- The property instance to bind the text of the wrapped text component to.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException
- if the specified property isnull
.IllegalArgumentException
- if the specified property allowsnull
values.
-
withText
Binds the text of the wrapped
to the specifiedTextComponent
Val
property instance so that the text of the wrapped text component is dynamically updated whenever the value of the property changes.This method is the same as
withText(Val)
except that theVar
property is used instead of theVal
property which allows for the text of the wrapped text component to be changed by the user.- Parameters:
text
- The property instance to bind the text of the wrapped text component to.- Returns:
- This very builder to allow for method chaining.
- Throws:
IllegalArgumentException
- if the specified property isnull
.IllegalArgumentException
- if the specified property allowsnull
values.
-
_setTextSilently
-
withFont
Use this to set the font of the wrappedJTextComponent
.- Parameters:
font
- The font of the text which should be displayed on the text component.- Returns:
- This builder instance, to allow for method chaining.
- Throws:
IllegalArgumentException
- iffont
isnull
.
-
withFont
Use this to dynamically set the font of the wrappedJTextComponent
through the provided view model property. When the font wrapped by the provided property changes, then so does the font of this text component.- Parameters:
font
- The font property of the text which should be displayed on the text component.- Returns:
- This builder instance, to allow for method chaining.
- Throws:
IllegalArgumentException
- iffont
isnull
.IllegalArgumentException
- iffont
is a property which can wrapnull
.
-
isEditableIf
Use this to modify the components' modifiability.- Parameters:
isEditable
- The flag determining if the underlyingJTextComponent
should be editable or not.- Returns:
- This very builder to allow for method chaining.
-
onContentChange
public final I onContentChange(sprouts.Action<ComponentDelegate<JTextComponent, DocumentEvent>> action) Use this to register any change in the contents of the text component including both the displayed text and its attributes.- Parameters:
action
- An action which will be executed when the text or its attributes in the underlyingJTextComponent
changes.- Returns:
- This very builder to allow for method chaining.
-
onTextChange
Use this to register if the text in this text component changes. This does not include style attributes like font size.- Parameters:
action
- An action which will be executed when the text string in the underlyingJTextComponent
changes.- Returns:
- This very builder to allow for method chaining.
-
_onTextChange
-
onTextRemove
Allows you to register a user action listener which will be called whenever parts (or all) of the text in the underlying text component gets removed. This event is based on theDocumentFilter.remove(DocumentFilter.FilterBypass, int, int)
method of the underlyingAbstractDocument
.- Parameters:
action
- AAction
lambda which will be called when parts (or all) of the text in the underlying text component gets removed.- Returns:
- This very builder to allow for method chaining.
-
onTextInsert
Allows you to register a user action listener which will be called whenever new text gets inserted into the underlying text component. This event is based on theDocumentFilter.insertString(DocumentFilter.FilterBypass, int, String, AttributeSet)
method of the underlyingAbstractDocument
. Use theTextInsertDelegate
that is supplied to your action to get access to the underlying text component and the text insertion details.- Parameters:
action
- AAction
lambda which will be called when new text gets inserted into the underlying text component.- Returns:
- This very builder to allow for method chaining.
-
onTextReplace
This method allows you to register a user action which will be called whenever the text in the underlying text component gets replaced. This event is based on theDocumentFilter.replace(DocumentFilter.FilterBypass, int, int, String, AttributeSet)
method of the underlyingAbstractDocument
. Use theTextReplaceDelegate
that is supplied to your action to get access to the underlying text component and the text replacement details.- Parameters:
action
- AAction
lambda which will be called when the text in the underlying text component gets replaced.- Returns:
- This very builder to allow for method chaining.
-