在 JavaFX 2 中,我通过读取 Excel 文件填充了 TableView。它看起来像这样:
identification cellcount calved
o0001 12345 false
o0002 65432 true
o0003 55555 false
...
当用户按下“导入”按钮时,所有记录都必须添加到数据库中。但是,如果“产犊”字段的值为“真”,我会显示一个对话框窗口,用户必须在其中选择一个日期来指定产犊发生的时间。现在最大的问题是我希望我的 for 循环在对话框窗口打开后立即暂停。使用我当前的代码,所有对话框窗口都堆叠在一起。
这是加载 FXML 的 Dialog 方法:
public void showDialog(String sURL){
final Stage myDialog = new Stage();
myDialog.initStyle(StageStyle.UTILITY);
myDialog.initModality(Modality.APPLICATION_MODAL);
URL url = getClass().getResource(sURL);
FXMLLoader fxmlloader = new FXMLLoader();
fxmlloader.setLocation(url);
fxmlloader.setBuilderFactory(new JavaFXBuilderFactory());
try {
Node n = (Node) fxmlloader.load(url.openStream());
Scene myDialogScene = new Scene(VBoxBuilder.create().children(n).alignment(Pos.CENTER).padding(new Insets(0)).build());
myDialog.setScene(myDialogScene);
myDialog.show();
} catch (Exception ex) {
System.out.println(ex);
}
}
这是我处理 tablerows 的 for 循环:
@FXML
private void handle_ImportCowDataButton(ActionEvent event) {
Cows selectedCow;
for(ImportRow row: tblImport.getItems()){
selectedCow = null;
for (Cows cow : olCows) {
if (cow.getOfficial().equals(row.getCownumber())) {
selectedCow = cow;
}
}
if (selectedCow != null) {
if (row.getCalving()) {
//if cow exists and cow has calved, show dialog window loading addcalving.fxml
//then the for loop should wait until that dialog window is closed before continuing
Context.getInstance().setPassthroughObject(selectedCow);
Context.getInstance().showDialog("/GUI/calving/AddCalving.fxml");
}
} else {
//if cow does not exist, show dialog window loading addcow.fxml
//then the for loop should wait until that dialog window is closed before continuing
Context.getInstance().setPassthroughObject(selectedFarmer);
Context.getInstance().showDialog("/GUI/cow/AddCow.fxml");
}
}
}
在setOnCloseRequest()
我的showDialog()
方法中使用是一种选择吗?