0
我有一个名为Tree
JavaFX - 将ObjectProperty绑定到另一个ObjectProperty中的成员?
public class Tree
{
private Color c;
public Color getColor()
{
return c;
}
}
类我有一个ObjectProperty
...
ObjectProperty<Tree> importantTree = new SimpleObjectProperty();
我要让Color
类型总是等于importantTree.get().getColor()
的另一个ObjectProperty
。每当Tree发生变化时,我都希望其他ObjectProperty更改为Tree的颜色。
例如。
ObjectProperty<Tree> importantTree = new SimpleObjectProperty();
ObjectProperty<Color> importantTreesColor = ...
Tree a = new Tree(Color.RED);
Tree b = new Tree(Color.GREEN);
importantTree.set(a);
System.out.println(importantTreesColor.get()); // This should print RED.
importantTree.set(b);
System.out.println(importantTreesColor.get()); // This should print GREEN.
绑定与属性有什么区别? – Hatefiend
通常可以设置属性,并且大多数实现都包含实际值。绑定只是绑定到一个或多个其他可观察值。请参阅相关的[文档](http://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Binding.html)或[tutorial](http://www.oracle.com)/PLS /主题/查找?CTX = javase80&ID = JFXBD107)。 –
太棒了,我明白了。和往常一样,你太棒了。我希望我能吸收你对JavaFX知道的所有信息 – Hatefiend