Class ComponentBinder


  • public class ComponentBinder
    extends java.lang.Object
    Utiltiy methods for binding ObservableBeans and change handlers to UI components.
    • Constructor Summary

      Constructors 
      Constructor Description
      ComponentBinder()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends javax.swing.JTextField>
      T
      bind​(ObservableBean source, java.lang.String propertyName, java.lang.Object currentValue, T field, java.text.Format format)
      Add a listener that updates a text field when a bean property changes.
      static <T extends javax.swing.text.JTextComponent>
      T
      bind​(T field, java.util.function.Consumer<java.lang.String> consumer)
      Add a listener that calls a Consumer when a text field changes.
      static <T extends javax.swing.text.JTextComponent,​V>
      T
      bind​(T field, java.util.function.Function<java.lang.String,​V> parser, java.util.function.Consumer<V> consumer)
      Add a listener that calls a Consumer when a text field changes.
      static <T extends javax.swing.text.JTextComponent>
      T
      onChange​(T field, java.lang.Runnable handler)
      Add a listener that calls a Runnable when a text field changes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ComponentBinder

        public ComponentBinder()
    • Method Detail

      • bind

        public static <T extends javax.swing.JTextField> T bind​(ObservableBean source,
                                                                java.lang.String propertyName,
                                                                java.lang.Object currentValue,
                                                                T field,
                                                                java.text.Format format)
        Add a listener that updates a text field when a bean property changes.
        Parameters:
        source - the source bean
        propertyName - the bean property name
        currentValue - the current value of the bean property
        field - the field to update (typically not editable)
        format - formatter for the value
        Returns:
        the text field
      • onChange

        public static <T extends javax.swing.text.JTextComponent> T onChange​(T field,
                                                                             java.lang.Runnable handler)
        Add a listener that calls a Runnable when a text field changes.
        Type Parameters:
        T - the text field class
        Parameters:
        field - the text field
        handler - the runnable to call
        Returns:
        the text field
      • bind

        public static <T extends javax.swing.text.JTextComponent> T bind​(T field,
                                                                         java.util.function.Consumer<java.lang.String> consumer)
        Add a listener that calls a Consumer when a text field changes.
        Type Parameters:
        T - the text field class
        Parameters:
        field - the text field
        consumer - the consumer to call
        Returns:
        the text field
      • bind

        public static <T extends javax.swing.text.JTextComponent,​V> T bind​(T field,
                                                                                 java.util.function.Function<java.lang.String,​V> parser,
                                                                                 java.util.function.Consumer<V> consumer)
        Add a listener that calls a Consumer when a text field changes.
        Type Parameters:
        T - the text field class
        V - the consumer value class
        Parameters:
        field - the text field
        parser - a function that parses the field value
        consumer - the consumer to call
        Returns:
        the text field
      • bind

        public static <T extends javax.swing.JPasswordField> T bind​(T field,
                                                                    java.util.function.Consumer<java.lang.String> consumer)
        Add a listener that calls a Consumer when a password field changes.
        Type Parameters:
        T - the password field class
        Parameters:
        field - the text field
        consumer - the consumer to call
        Returns:
        the password field