定義在嵌套控制器可觀察到的特性,並從周圍的控制器觀察它:
public class ChildController {
private final BooleanProperty stuffShouldBeDisabled = new SimpleBooleanProperty();
public BooleanProperty stuffShouldBeDisabledProperty() {
return stuffShouldBeDisabled ;
}
public final boolean getStuffShouldBeDisabled() {
return stuffShouldBeDisabledProperty().get();
}
@FXML
private void handleButtonClick(ActionEvent event) {
stuffShouldBeDisabled.set(! stufShouldBeDisabled.get());
}
// ...
}
,然後在「周圍」(父)控制器(即控制器,用於與<fx:include>
的FXML文件標籤):
public class MainController {
@FXML
private ChildController childController ; // injected via <fx:include fx:id="child" ... />
@FXML
private Tab someTab ;
public void initialize() {
childController.stuffShouldBeDisabledProperty().addListener((obs, wasDisabled, isNowDisabled) -> {
someTab.setDisable(isNowDisabled);
}
}
// ...
}
非常感謝,我想這就是我要找的。當我回家時,我會仔細看看,看看我能否根據你的回答找出答案!非常感激 :) –