切换 FXML 后 Javafx 小部件没有响应
Javafx widget not responding after switching FXML
我的 javafx 应用程序必须在选择组合框中的项目后切换其 FXML 文件然而,组合框在切换后停止响应,但 FXML 添加的其他项目继续工作。我必须最小化和最大化应用程序以使其工作或使用 FXML 添加的小部件以使其响应。
comboBox.setOnAction(event -> {
calculatorType = comboBox.getValue();
switch (calculatorType) {
case "Basic":
System.out.println(root.getChildren());
root.getChildren().clear();
try {
stage.setMinWidth(430);
stage.setMinHeight(530);
stage.setMaxWidth(430);
stage.setMinHeight(530);
//root.getChildren().remove(comboBox);
root.getChildren().add(FXMLLoader.load(getClass().getResource("/Calculator/Resources" +
"/BasicCalculator.fxml")));
comboBox.setLayoutX(320);
comboBox.setLayoutY(0);
root.getChildren().add(comboBox);
} catch (IOException e) {
e.printStackTrace();
}
break;
case "Scientific":
root.getChildren().clear();
try {
stage.setMinHeight(530);
stage.setMinWidth(780);
stage.setMaxHeight(530);
stage.setMaxWidth(780);
root.getChildren().add(FXMLLoader.load(getClass().getResource("/Calculator/Resources/" +
"ScientificCalculator.fxml")));
comboBox.setLayoutX(675);
comboBox.setLayoutY(0);
root.getChildren().add(comboBox);
} catch (IOException e) {
e.printStackTrace();
}
break;
case "Converter":
root.getChildren().clear();
stage.setMinHeight(530);
stage.setMinWidth(430);
stage.setMaxHeight(530);
stage.setMaxWidth(430);
try {
root.getChildren().add(FXMLLoader.load(getClass().getResource("/Calculator/Resources/" +
"Converter.fxml")));
} catch (IOException e) {
e.printStackTrace();
}
comboBox.setLayoutX(320);
comboBox.setLayoutY(0);
root.getChildren().add(ComboPane);
break;
}
});
组合框在main.
组合框代码:
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getStylesheets().add("Calculator/Resources/Styles/ComboBox.css");
comboBox.getItems().add("Basic");
comboBox.getItems().add("Scientific");
comboBox.getItems().add("Converter");
comboBox.getSelectionModel().select(0);
comboBox.setLayoutX(320);
comboBox.setLayoutY(0);
谢谢。
我的 javafx 应用程序必须在选择组合框中的项目后切换其 FXML 文件然而,组合框在切换后停止响应,但 FXML 添加的其他项目继续工作。我必须最小化和最大化应用程序以使其工作或使用 FXML 添加的小部件以使其响应。
comboBox.setOnAction(event -> {
calculatorType = comboBox.getValue();
switch (calculatorType) {
case "Basic":
System.out.println(root.getChildren());
root.getChildren().clear();
try {
stage.setMinWidth(430);
stage.setMinHeight(530);
stage.setMaxWidth(430);
stage.setMinHeight(530);
//root.getChildren().remove(comboBox);
root.getChildren().add(FXMLLoader.load(getClass().getResource("/Calculator/Resources" +
"/BasicCalculator.fxml")));
comboBox.setLayoutX(320);
comboBox.setLayoutY(0);
root.getChildren().add(comboBox);
} catch (IOException e) {
e.printStackTrace();
}
break;
case "Scientific":
root.getChildren().clear();
try {
stage.setMinHeight(530);
stage.setMinWidth(780);
stage.setMaxHeight(530);
stage.setMaxWidth(780);
root.getChildren().add(FXMLLoader.load(getClass().getResource("/Calculator/Resources/" +
"ScientificCalculator.fxml")));
comboBox.setLayoutX(675);
comboBox.setLayoutY(0);
root.getChildren().add(comboBox);
} catch (IOException e) {
e.printStackTrace();
}
break;
case "Converter":
root.getChildren().clear();
stage.setMinHeight(530);
stage.setMinWidth(430);
stage.setMaxHeight(530);
stage.setMaxWidth(430);
try {
root.getChildren().add(FXMLLoader.load(getClass().getResource("/Calculator/Resources/" +
"Converter.fxml")));
} catch (IOException e) {
e.printStackTrace();
}
comboBox.setLayoutX(320);
comboBox.setLayoutY(0);
root.getChildren().add(ComboPane);
break;
}
});
组合框在main.
组合框代码:
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getStylesheets().add("Calculator/Resources/Styles/ComboBox.css");
comboBox.getItems().add("Basic");
comboBox.getItems().add("Scientific");
comboBox.getItems().add("Converter");
comboBox.getSelectionModel().select(0);
comboBox.setLayoutX(320);
comboBox.setLayoutY(0);
谢谢。