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

  • Home
  • SEARCH
  • 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 8491915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:34:08+00:00 2026-06-10T22:34:08+00:00

I have an application where I call the following code when an exception occurs-

  • 0

I have an application where I call the following code when an exception occurs- that is, it is located within the “catch” of a “try/catch”. It merely creates a “popup”-like window which tells the user to enter an int instead.

Stage dialogStage = new Stage();
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.setScene(new Scene(VBoxBuilder.create().
children(new Text("Please enter an integer."), new Button("Ok.")).
alignment(Pos.CENTER).padding(new Insets(5)).build()));
dialogStage.show();

The only problem is that the stage lingers even if the primary stage (that is the parameter in the public void start(Stage primaryStage)) is closed.

What have I tried?:

I made the dialogstage visible in the whole class by defining it as a class variable. Then I implemented the following code:

primaryStage.setOnCloseRequest((new EventHandler<WindowEvent>(){

        @Override
        public void handle(WindowEvent arg0) {
                            arg0.consume();
            try
            {
             dialogStage.close();

                            }
            catch(Exception ex)
            {
                System.out.print(ex.getMessage()+"\r\n");
            }

        }
    }));
}

This “works” in that the dialogstage is closed when a user tries to exit the main application, however, it does not actually do what I intended: when you try to close the primary stage only the dialogstage is closed.

It is also an aesthetically displeasing solution as I don’t want the whole class to know about the stupid dialog box which is only located in one try/catch and might never be used.

I’d like to know if there is a simple solution that tells the dialogstage to close when the primary stage does and where I don’t have to write much code outside of my try/catch.

  • 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-10T22:34:10+00:00Added an answer on June 10, 2026 at 10:34 pm

    On the event OnCloseRequest on your main stage, perform Platform.exit (docs.oracle.com/javafx/2/api/javafx/application/Platform.html)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that works fine when I call it from within the
I can call a macro from within my add-in with the following code: Application.Run(MACRO_NAME);
I have a method that looks like this: try { doStuff(); } catch (Exception
Consider the following code: try { include_once malformedFile.php; } catch(Exception $e) { return null;
I have created one dynamic button in my application and I call the following
I have the following views in my application. Basically I want to call show_house()
I have DLL and application that will call some function in this dll. For
I have an application that I make a call to a DLL function that
I have an application in which I have a webservice call that returns data
I have an application that consists of two processes (let's call them A and

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.