我想在Radiobuttons之间切换FXML文件而不会丢失Combobox-Selection。 “secSelectionModel()”似乎添加了一个Selection,但它没有直观显示。
public class Controller {
static SingleSelectionModel cbxSelection;
@FXML private ComboBox<String> cbx = new ComboBox<>();
@FXML private RadioButton radio1 = new RadioButton();
@FXML private RadioButton radio2 = new RadioButton();
@FXML private void cbxFill(){
cbx.getItems().setAll("eins","zwei");
}
@FXML private void screenSwitch() throws IOException {
Stage stage;
Parent root;
if(radio1.isSelected()){
stage=(Stage) radio1.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("sample.fxml"));
//cbxFill();
cbx.setSelectionModel(cbxSelection);
}
else{
stage=(Stage) radio2.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("sample2.fxml"));
//cbxFill();
cbx.setSelectionModel(cbxSelection);
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@FXML private void getcbxSelection(){
cbxSelection=cbx.getSelectionModel();
}
}