Package swingtree

Class UIForTextField<F extends JTextField>


public final class UIForTextField<F extends JTextField> extends UIForAnyTextComponent<UIForTextField<F>,F>
A SwingTree builder node designed for configuring JTextField 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 or other classes.

  • Method Details

    • _state

      protected swingtree.BuilderState<F> _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<UIForTextField<F extends JTextField>,F extends JTextField,JComponent>
      Returns:
      The state of the builder.
    • _newBuilderWithState

      protected UIForTextField<F> _newBuilderWithState(swingtree.BuilderState<F> 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<UIForTextField<F extends JTextField>,F extends JTextField,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.
    • onEnter

      public UIForTextField<F> onEnter(sprouts.Action<ComponentDelegate<F,ActionEvent>> action)
      Allows you to register an action to be performed when the user presses the enter key.
      Parameters:
      action - The action to be performed.
      Returns:
      This very instance, which enables builder-style method chaining.
    • withNumber

      public final <N extends Number> UIForTextField<F> withNumber(sprouts.Var<N> number)
      Effectively bind this text field to a numeric Var property which will only accept numbers as input.
      Type Parameters:
      N - The numeric type of the Var property.
      Parameters:
      number - The numeric Var property to bind to.
      Returns:
      This builder node.
    • withNumber

      public final <N extends Number> UIForTextField<F> withNumber(sprouts.Var<N> number, sprouts.Var<Boolean> isValid)
      Effectively bind this text field to a numeric Var property which will only accept numbers as input.
      Type Parameters:
      N - The numeric type of the Var property.
      Parameters:
      number - The numeric Var property to bind to.
      isValid - A Var property which will be set to true if the input is valid, and false otherwise.
      Returns:
      This builder node.
    • withNumber

      public final <N extends Number> UIForTextField<F> withNumber(sprouts.Var<N> number, Function<N,String> formatter)
      Binds this text field to a numeric Var property which will only accept numbers as input and a custom formatter which turns the number into a string.
      Type Parameters:
      N - The numeric type of the Var property.
      Parameters:
      number - The numeric Var property to bind to.
      formatter - A function which will be used to format the number as a string.
      Returns:
      This builder node.
    • withNumber

      public final <N extends Number> UIForTextField<F> withNumber(sprouts.Var<N> number, sprouts.Var<Boolean> isValid, Function<N,String> formatter)
      Effectively bind this text field to a numeric Var property which will only accept numbers as input.
      Type Parameters:
      N - The numeric type of the Var property.
      Parameters:
      number - The numeric Var property to bind to.
      isValid - A Var property which will be set to true if the input is valid, and false otherwise.
      formatter - A function which will be used to format the number as a string.
      Returns:
      This builder node.
    • withNumber

      public final <N extends Number> UIForTextField<F> withNumber(sprouts.Val<N> number)
      Effectively bind this text field to a numeric Val property but only for reading purposes. So the text field will be updated when the Val property changes but the user will not be able to change the Val property since the Val property is read-only.
      Type Parameters:
      N - The numeric type of the Val property.
      Parameters:
      number - The numeric Val property to bind to.
      Returns:
      This builder node.
    • withTextOrientation

      public final UIForTextField<F> withTextOrientation(UI.HorizontalAlignment orientation)
      The provided UI.HorizontalAlignment translates to JTextField.setHorizontalAlignment(int) instances which are used to align the elements or text within the wrapped JTextComponent. LayoutManager and Component subclasses will use this property to determine how to lay out and draw components.

      Note: This method indirectly changes layout-related information, and therefore, invalidates the component hierarchy.

      Parameters:
      orientation - The text orientation type which should be used.
      Returns:
      This very builder to allow for method chaining.
    • withPlaceholder

      public final UIForTextField<F> withPlaceholder(String placeholder)
      Sets the placeholder text of this text field to a static string. The placeholder text will not change.
      Use withPlaceholder(Val) to bind the placeholder text to a Val property, so that the placeholder text can change dynamically when the property state changes.
      Parameters:
      placeholder - The placeholder text to set.
      Returns:
      This UI builder node, to allow for method chaining.
    • withPlaceholder

      public final UIForTextField<F> withPlaceholder(sprouts.Val<String> placeholder)
      Binds the placeholder text of this text field to a Val property. When the item of the Val property changes, the placeholder text will be updated accordingly.
      Parameters:
      placeholder - The placeholder property which will be listened to for changes.
      Returns:
      This UI builder node, to allow for method chaining.