Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:13:50+00:00 2026-06-14T18:13:50+00:00

In JavaFX 2 I have a TableView beeing populated by reading an Excel file.

  • 0

In JavaFX 2 I have a TableView beeing populated by reading an Excel file. It looks like this:

identification    cellcount    calved
o0001             12345        false
o0002             65432        true
o0003             55555        false
...

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.

This is the Dialog method which loads an FXML:

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);
    }
}

And here is the for loop where I handle the tablerows:

@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");
        }
    }
}

Is working with setOnCloseRequest() in my showDialog() method an option?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:13:51+00:00Added an answer on June 14, 2026 at 6:13 pm

    It seems the answer was much easier then I thought, simply use the showAndWait() method instead of show(). How on earth could I have missed that… Thanks for the help thou.

    Final code of the showDialog() method:

    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.showAndWait();
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have applied CSS style to JavaFX components and it looks like everything is
I have a JavaFX app with a some code like this... public class MainListener
i have a little problem with javafx. i added a change listener like this:
I have this easy little form in my JavaFX application. I want to use
I have a very simple fxml file, with a checkbox: ... <AnchorPane id=AnchorPane xmlns:fx=http://javafx.com/fxml
I'm learning JavaFX and this is just a small programming question. I have 3
I have this kind of progamming task without JavaFx, instead it's Java Swing. I
I have installed JavaFX 2.0 SDK and now I would like to do an
I have a jnlp file for deploying my javafx 2.0 application, however, how do
I have JavaFX application using FXML to build its GUI. When this application is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.