1

我正在使用eclipse jee photon 和scenebuilder。

我正在尝试做的事情:我有一个带有两个标签的选择框: ObservableList labelList = FXCollections.observableArrayList("examlpe01", "example02");

如果选择了 example01,则该复选框应该可见但禁用。如果选择了 example02,则该复选框应该是可见的并且应该可以检查它。


这是我的代码:

public class newUser{

    ObservableList <String> labelList = FXCollections.observableArrayList("example01", "example02");

    @FXML
    private TextField name;

    @FXML
    private TextField lastName;

    @FXML
    private Button saveUser;

    @FXML
    private CheckBox adminRights;

    @FXML
    private TextField emailAdress;

    @FXML
    private TextField password;

    @FXML
    private Button userSpeichern;

    @FXML
    private MenuButton userDropDown;

    @FXML
    private MenuItem adminpage;

    @FXML
    private MenuItem example01;

    @FXML
    private MenuItem example02;

    @FXML
    private MenuItem logout;

    @FXML
    private ChoiceBox label;

    @FXML
    private void initialize() {
    label.setItems(labelList);
    label.setValue("mm");
    }

    @FXML
    void logout(ActionEvent event) throws IOException {
    Parent Login = FXMLLoader.load(getClass().getClassLoader().getResource("fxml/Login.fxml"));
    Scene Login_scene = new Scene(Login);
    Stage app_stage = (Stage) userDropDown.getScene().getWindow();
    app_stage.setScene(Login_scene);
    app_stage.show();

    }

    DbHelper db = new DbHelper();

    private void showCheckbox() {
    if (label.equals("example02")) {

        }
    }

     @FXML
     void saveUserData(ActionEvent event) {   
}
4

1 回答 1

0

用这个:

@FXML
ChoiceBox choiceBox;

@FXML
CheckBox checkBox;

@FXML
private void choiceBoxOnClicked() {
    if (choiceBox.getValue().equals("example01")) {
        checkBox.setDisable(true);
    } else if (choiceBox.getValue().equals("example02")) {
        checkBox.setDisable(false);
    }
}

所以这应该有效。

于 2019-07-23T12:55:34.827 回答