本文整理匯總了Java中javafx.beans.property.Property.addListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Property.addListener方法的具體用法?Java Property.addListener怎麽用?Java Property.addListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.beans.property.Property
的用法示例。
在下文中一共展示了Property.addListener方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bindToMapBidirectionally
import javafx.beans.property.Property; //導入方法依賴的package包/類
/**
* Binds a property to a specific key in a map. If there is no entry for that key, the property's
* value will be set to null.
*
* @param property the property to bind
* @param map the map to bind to
* @param key the key for the entry to bind to
* @param v2t a conversion function for converting objects of type <i>V</i> to type <i>T</i>
* @param <K> the types of the keys in the map
* @param <V> the types of the values in the map
* @param <T> the type of data in the property
*/
public static <K, V, T extends V> void bindToMapBidirectionally(Property<T> property,
ObservableMap<K, V> map,
K key,
Function<V, T> v2t) {
property.addListener((__, oldValue, newValue) -> map.put(key, newValue));
map.addListener((MapChangeListener<K, V>) change -> {
if (change.getKey().equals(key)) {
if (change.wasRemoved() && !map.containsKey(key)) {
property.setValue(null);
} else if (change.wasAdded()) {
property.setValue(v2t.apply(change.getValueAdded()));
}
}
});
}
示例2: setProgressProperty
import javafx.beans.property.Property; //導入方法依賴的package包/類
/**
* Sets the progress property to scrub.
*/
public void setProgressProperty(Property<Number> progressProperty) {
Objects.requireNonNull(progressProperty, "progressProperty");
if (this.progressProperty != null) {
this.progressProperty.removeListener(progressListener);
}
this.progressProperty = progressProperty;
progressProperty.addListener(progressListener);
}
示例3: bindBidirectional
import javafx.beans.property.Property; //導入方法依賴的package包/類
/**
* Creates a bidirectional binding between the two given properties of different types via the
* help of a {@link Converter}.
*
* @param leftProperty the left property
* @param rightProperty the right property
* @param converter the converter
* @param <L> the type of the left property
* @param <R> the type of the right property
*/
public static <L, R> void bindBidirectional(Property<L> leftProperty, Property<R> rightProperty, Converter<L, R> converter) {
BidirectionalConversionBinding<L, R> binding = new BidirectionalConversionBinding<>(leftProperty, rightProperty, converter);
leftProperty.addListener(binding);
rightProperty.addListener(binding);
leftProperty.setValue(converter.toLeft(rightProperty.getValue()));
}