Java Reference
In-Depth Information
public JavaBeanStringPropertyBuilder beanClass(java.lang.Class<?>)
public JavaBeanStringPropertyBuilder getter(java.lang.String)
public JavaBeanStringPropertyBuilder setter(java.lang.String)
public JavaBeanStringPropertyBuilder getter(java.lang.reflect.Method)
public JavaBeanStringPropertyBuilder setter(java.lang.reflect.Method)
To use the builder, start by calling its static method
create()
. Then call a chain of the methods that returns the
builder itself. Finally, the
build()
method is called to create the property. For most cases, it suffices to call the
bean()
and the
name()
methods to specify the JavaBean instance and the name of the property. The
getter()
and
setter()
methods can be used to specify a getter and setter that does not follow the naming convention. The
beanClass()
method can be used to specify the JavaBean class. Setting the JavaBean class up front on the builder allows you to
more efficiently create adapters for the same JavaBeans property for multiple instances of the same JavaBean class.
■
although the builders of the JavaFX scene, control, and so on, classes have been deprecated, the builders in
the
javafx.beans.property.adapter
package have not been deprecated. they are required to generate the JavaBeans
property adapters.
Note
The program in Listing 4-17 illustrates the adaption of the three JavaBeans properties of the
Person
class into
JavaBeanStringProperty
objects.
Listing 4-17.
JavaBeanPropertiesExamples.java
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.adapter.JavaBeanStringProperty;
import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder;
import java.beans.PropertyVetoException;
public class JavaBeanPropertiesExample {
public static void main(String[] args) throws NoSuchMethodException {
adaptJavaBeansProperty();
adaptBoundProperty();
adaptConstrainedProperty();
}
private static void adaptJavaBeansProperty() throws NoSuchMethodException {
Person person = new Person();
JavaBeanStringProperty nameProperty = JavaBeanStringPropertyBuilder.create()
.bean(person)
.name("name")
.build();
nameProperty.addListener((observable, oldValue, newValue) -> {
System.out.println("JavaFX property " + observable + " changed:");
System.out.println("\toldValue = " + oldValue + ", newValue = " + newValue);
});
System.out.println("Setting name on the JavaBeans property");
person.setName("Weiqi Gao");
System.out.println("Calling fireValueChange");
Search WWH ::
Custom Search