禁用controlsFX WizardPane中的“下一步”按钮?

时间:2019-03-16 23:36:36

标签: javafx binding dialog wizard controlsfx

在我的JavaFX项目中,我包括使用Linear.Flow的controlsFX向导。对于我的WizardPane之一,我希望将Next按钮的Disabled属性绑定到boolean属性。 (更具体地说,如果TextField为空,则应禁用该按钮。)

但是,我找不到任何解决方案。 (here提供的可能的解决方案对我不起作用。

这是我的WizardPane:

private WizardPane getName() {
    TextField textField = new TextField();
    textField.requestFocus();

    final WizardPane namePane = new WizardPane();

    namePane.setHeaderText("Choose Name for File");

    final GridPane grid = new GridPane();

    grid.add(new Label("File Name:"), 0, 0);
    grid.add(textField, 1, 0);

    namePane.setContent(grid);

    return namePane;
}

我绑定残疾人属性的尝试失败,如下所示:

@Override
public void onEnteringPage(Wizard wizard) {
    this.getButtonTypes()
                .stream()
                .filter(type -> type.getButtonData().equals(ButtonBar.ButtonData.NEXT_FORWARD))
                .map(this::lookupButton)
                .findFirst()
                .ifPresent(next -> next.disableProperty().bind(textField.textProperty().isEmpty()));
}

任何建议,不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

原来,我确实过于复杂了。解决方案只是绑定向导的invalidProperty

Wizard wiz = new Wizard();
wiz.invalidProperty().bind(textField.textProperty().isEmpty());