Mastering JavaFX 10
上QQ阅读APP看书,第一时间看更新

Binding is a one-to-many relation

Any property can be observed as many times as you want:

Label lblWidth = new Label();
Label lblWidth2 = new Label();

lblWidth.textProperty().bind(stage.widthProperty().asString());
lblWidth2.textProperty().bind(stage.widthProperty().asString());

But, any consecutive call for the bind() method will override the previous one:

lblWidth.textProperty().bind(stage.widthProperty().asString());
lblWidth.textProperty().bind(stage.heightProperty().asString());
// now lblWidth listens for height and ignores width

Don't be disappointed by this rule. You can call bind() effectively only once, right. But, the parameter of bind() can be much more complex than just one property. We'll discuss this in more detail in the Using binding operations section.