У меня есть класс SimpleElement, который имеет поле веса, а второй имеет список SimpleElement и поле веса, которое зависит от суммы веса всех остальных простых элементов, содержащихся в списке. Кто-нибудь знает, как это сделать, привязывая?
Мой код:JavaFX: Как связать несколько свойств в списке?
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class SimpleElement {
IntegerProperty weight;
public SimpleElement() {
weight = new SimpleIntegerProperty();
}
public int getWeight() {
return weight.get();
}
public void setWeight(int weight) {
this.weight.set(weight);
}
public IntegerProperty weightProperty() {
return weight;
}
}
и
import java.util.ArrayList;
import java.util.List;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class RootElement {
List<SimpleElement> elements;
IntegerProperty weight;
public RootElement() {
elements = new ArrayList<>();
weight = new SimpleIntegerProperty();
}
public void addelements(SimpleElement element) {
elements.add(element);
}
}
Рассмотрите [EasyBind] Томаса Микулы (https://github.com/TomasMikula/EasyBind). –