Module javafx.base

Class JavaBeanObjectProperty<T>

  • All Implemented Interfaces:
    Observable, JavaBeanProperty<T>, ReadOnlyJavaBeanProperty<T>, Property<T>, ReadOnlyProperty<T>, ObservableObjectValue<T>, ObservableValue<T>, WritableObjectValue<T>, WritableValue<T>

    public final class JavaBeanObjectProperty<T>
    extends ObjectProperty<T>
    implements JavaBeanProperty<T>
    A JavaBeanObjectProperty provides an adapter between a regular Java Bean property of type T and a JavaFX ObjectProperty<T>. It cannot be created directly, but a JavaBeanObjectPropertyBuilder has to be used.

    As a minimum, the Java Bean class must implement a getter and a setter for the property. The class, as well as the getter and a setter methods, must be declared public. If the getter of an instance of this class is called, the property of the Java Bean is returned. If the setter is called, the value will be passed to the Java Bean property. If the Java Bean property is bound (i.e. it supports PropertyChangeListeners), this JavaBeanObjectProperty will be aware of changes in the Java Bean. Otherwise it can be notified about changes by calling fireValueChangedEvent(). If the Java Bean property is also constrained (i.e. it supports VetoableChangeListeners), this JavaBeanObjectProperty will reject changes, if it is bound to an ObservableValue<Object>.

    Deploying an Application as a Module

    If the Java Bean class is in a named module, then it must be reflectively accessible to the javafx.base module. A class is reflectively accessible if the module opens the containing package to at least the javafx.base module.

    For example, if com.foo.MyBeanClass is in the foo.app module, the module-info.java might look like this:

    module foo.app {
        opens com.foo to javafx.base;
    }

    Alternatively, a class is reflectively accessible if the module exports the containing package unconditionally.

    Since:
    JavaFX 2.1
    See Also:
    ObjectProperty, JavaBeanObjectPropertyBuilder
    • Method Detail

      • bind

        public void bind​(ObservableValue<? extends T> observable)
        Create a unidirection binding for this Property.

        Note that JavaFX has all the bind calls implemented through weak listeners. This means the bound property can be garbage collected and stopped from being updated.

        Specified by:
        bind in interface Property<T>
        Parameters:
        observable - The observable this Property should be bound to.
      • getBean

        public Object getBean()
        Returns the Object that contains this property. If this property is not contained in an Object, null is returned.
        Specified by:
        getBean in interface ReadOnlyProperty<T>
        Returns:
        the containing Object or null
      • getName

        public String getName()
        Returns the name of this property. If the property does not have a name, this method returns an empty String.
        Specified by:
        getName in interface ReadOnlyProperty<T>
        Returns:
        the name or an empty String
      • addListener

        public void addListener​(ChangeListener<? super T> listener)
        Adds a ChangeListener which will be notified whenever the value of the ObservableValue changes. If the same listener is added more than once, then it will be notified more than once. That is, no check is made to ensure uniqueness.

        Note that the same actual ChangeListener instance may be safely registered for different ObservableValues.

        The ObservableValue stores a strong reference to the listener which will prevent the listener from being garbage collected and may result in a memory leak. It is recommended to either unregister a listener by calling removeListener after use or to use an instance of WeakChangeListener avoid this situation.

        Specified by:
        addListener in interface ObservableValue<T>
        Parameters:
        listener - The listener to register
        See Also:
        ObservableValue.removeListener(ChangeListener)
      • removeListener

        public void removeListener​(ChangeListener<? super T> listener)
        Removes the given listener from the list of listeners that are notified whenever the value of the ObservableValue changes.

        If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed.

        Specified by:
        removeListener in interface ObservableValue<T>
        Parameters:
        listener - The listener to remove
        See Also:
        ObservableValue.addListener(ChangeListener)
      • addListener

        public void addListener​(InvalidationListener listener)
        Adds an InvalidationListener which will be notified whenever the Observable becomes invalid. If the same listener is added more than once, then it will be notified more than once. That is, no check is made to ensure uniqueness.

        Note that the same actual InvalidationListener instance may be safely registered for different Observables.

        The Observable stores a strong reference to the listener which will prevent the listener from being garbage collected and may result in a memory leak. It is recommended to either unregister a listener by calling removeListener after use or to use an instance of WeakInvalidationListener avoid this situation.

        Specified by:
        addListener in interface Observable
        Parameters:
        listener - The listener to register
        See Also:
        Observable.removeListener(InvalidationListener)
      • removeListener

        public void removeListener​(InvalidationListener listener)
        Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

        If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed.

        Specified by:
        removeListener in interface Observable
        Parameters:
        listener - The listener to remove
        See Also:
        Observable.addListener(InvalidationListener)
      • fireValueChangedEvent

        public void fireValueChangedEvent()
        This method can be called to notify the adapter of a change of the Java Bean value, if the Java Bean property is not bound (i.e. it does not support PropertyChangeListeners).
        Specified by:
        fireValueChangedEvent in interface ReadOnlyJavaBeanProperty<T>
      • dispose

        public void dispose()
        Signals to the JavaFX property that it will not be used anymore and any references can be removed. A call of this method usually results in the property stopping to observe the Java Bean property by unregistering its listener(s).
        Specified by:
        dispose in interface ReadOnlyJavaBeanProperty<T>
      • toString

        public String toString()
        Returns a string representation of this JavaBeanObjectProperty object.
        Overrides:
        toString in class ObjectProperty<T>
        Returns:
        a string representation of this JavaBeanObjectProperty object.