Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to wait for input in a for loop?
    text
    copied!<p>In JavaFX 2 I have a TableView beeing populated by reading an Excel file. It looks like this:</p> <pre><code>identification cellcount calved o0001 12345 false o0002 65432 true o0003 55555 false ... </code></pre> <p>When users press the 'Import' button, all records have to be added to a database. However, If the 'calved' field has 'true' as value, I show a Dialog window where the users have to select a date to specify when the calving happened. Now the big question is that I want my for loop beeing paused as soon as a Dialog window is open. With my current code, all Dialog windows are stacked on eachother.</p> <p>This is the Dialog method which loads an FXML:</p> <pre><code>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); } } </code></pre> <p>And here is the for loop where I handle the tablerows:</p> <pre><code>@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"); } } } </code></pre> <p>Is working with <code>setOnCloseRequest()</code> in my <code>showDialog()</code> method an option?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload