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 8786469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:38:08+00:00 2026-06-13T21:38:08+00:00

I want to handle stage events (i.e. hiding) from my controller class. So all

  • 0

I want to handle stage events (i.e. hiding) from my controller class. So all I have to do is to add a listener like this:

((Stage) myPane.getScene().getWindow()).setOn*whatIwant*(...);

But the problem is that initialization starts right after this code:

Parent root = FXMLLoader.load(getClass().getResource("MyGui.fxml"));

And before this code:

Scene scene = new Scene(root);
stage.setScene(scene);

Thus getScene returns null.

The only workaround I found by myself is to add a listener to myPane.sceneProperty, and when it becomes not null I get scene, add to it’s windowProperty my listener handling which I finally retrieve stage. And it all ends with setting desired listeners to stage events.

I think there are too many listeners.

Is it the only way to solve my problem?

  • 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-13T21:38:10+00:00Added an answer on June 13, 2026 at 9:38 pm

    You can get the instance of the controller from the FXMLLoader after initialization via getController(), but you need to instantiate an FXMLLoader instead of using the static methods then.

    I’d pass the stage after calling load() directly to the controller afterwards:

    FXMLLoader loader = new FXMLLoader(getClass().getResource("MyGui.fxml"));
    Parent root = (Parent)loader.load();
    MyController controller = (MyController)loader.getController();
    controller.setStageAndSetupListeners(stage); // or what you want to do
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a frame extends from JWindow (because I want to handle my X
i have a tlf text input in stage,i want dispatch ahndler for this object
I want to handle mouse click in a native MFC application from a C#
I want to handle events on a treeview with ACB ( http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/ ). I
I have an input box which I want to handle two types of information,
I have an ATL app where I want to handle WM_POWERBROADCAST . I have
So I want to have tabs with default style but I want to handle
If I make a state machine and want to use an interface like this:
I want to add an event to the List generic class in C# in
To set the stage, I have a custom class called Scheduler that holds multiple

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.