How to get name of currently loaded fxml file?

Alyona

I have BorderPane, which is divided to 3 AnchorPanes that are changing time to time. Is it possible to get full .fxml file name like 'MainScreen.fxml'? I can get AnchorPane with System.out.println(getRootLayout().getCenter());, but I can't figure out how to get it's name.

It's just I need to call from main class for method that is located in one of my controllers. But I want to call it only if certain fxml file for that controller is currently in use.

In short: if MainScreen.fxml is in use I will call it's MainScreenController's method, if not, then I won't.

Prometheus

Based on your question I assume that each AnchorPane is loaded from a different FXML file and that you keep a reference to their controllers in your application.

A simple solution would be to put the file information into the controller.

You can either do this manually...

URL location = getClass().getResource("MainScreen.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
// ... more fxmlLoader configuration ...
fxmlLoader.load();

// assuming your own Controller class has a setLocation method
Controller c = (Controller) fxmlLoader.getController();
c.setLocation(location);

... or rely on the FXMLLoader.

// your own Controller class
public class Controller
{
    // the URL will be automatically injected by the FXMLLoader
    // careful: the name of the field must be 'location'
    @FXML
    private URL location;

    // ...
}

Then you can simply add a getLocation() method to your controller to check from which file it was loaded.

However, there is probably a better solution for your underlying problem that does not require checking for a specific file name.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get name of currently loaded fxml file?

From Dev

How to get the file name of ms word which is currently open

From Java

How do I get the path and name of the file that is currently executing?

From Dev

How can I get the file name of currently running process?

From Dev

swift, How to get currently displayed image file name from UIImageView

From Dev

get name of the file loaded by @PropertySource

From Dev

How to get an imageView in a fxml file

From Dev

How to get the name of the currently active window in Python?

From Dev

Roslyn: How to get a reference to Workspace from currently loaded solution?

From Dev

How to get the image currently loaded in WebBrowser control .NET

From Dev

How do I get in R the name of currently executed script when called via `r BATCH script file`

From Dev

How can I get the name of the file I'm currently visiting with Clang?

From Java

How to get the directory of the currently running file?

From Dev

How to `getTopActivity` name or get currently running application package name in lollipop?

From Dev

Get name of a resource currently loaded in TImage component - Delphi XE3

From Dev

How to copy file name of currently opened file in sublime text 3?

From Dev

how to get the timezone name which are currently set in my Codeigniter application

From Dev

How do I get the name of the target that is currently running in Xcode?

From Dev

How can I get the name of the currently executing Meteor method?

From Dev

XMPPFramework - How to get currently logged-in user's display name

From Dev

How to get the name of currently running app in an App for office 2013

From Dev

XMPPFramework - How to get currently logged-in user's display name

From Dev

How to get a list of unused kernel modules of currently running system? (Static and loaded)

From Dev

How to get the video file for a movie currently playing in browser?

From Dev

How to get the path to the currently included cmake file in a function?

From Dev

Intellij IDEA plugin how to get path of currently oppened file?

From Dev

How to get the video file for a movie currently playing in browser?

From Dev

Debian: How to get the current loaded kernel package name?

From Dev

Get path of currently marked file

Related Related

  1. 1

    How to get name of currently loaded fxml file?

  2. 2

    How to get the file name of ms word which is currently open

  3. 3

    How do I get the path and name of the file that is currently executing?

  4. 4

    How can I get the file name of currently running process?

  5. 5

    swift, How to get currently displayed image file name from UIImageView

  6. 6

    get name of the file loaded by @PropertySource

  7. 7

    How to get an imageView in a fxml file

  8. 8

    How to get the name of the currently active window in Python?

  9. 9

    Roslyn: How to get a reference to Workspace from currently loaded solution?

  10. 10

    How to get the image currently loaded in WebBrowser control .NET

  11. 11

    How do I get in R the name of currently executed script when called via `r BATCH script file`

  12. 12

    How can I get the name of the file I'm currently visiting with Clang?

  13. 13

    How to get the directory of the currently running file?

  14. 14

    How to `getTopActivity` name or get currently running application package name in lollipop?

  15. 15

    Get name of a resource currently loaded in TImage component - Delphi XE3

  16. 16

    How to copy file name of currently opened file in sublime text 3?

  17. 17

    how to get the timezone name which are currently set in my Codeigniter application

  18. 18

    How do I get the name of the target that is currently running in Xcode?

  19. 19

    How can I get the name of the currently executing Meteor method?

  20. 20

    XMPPFramework - How to get currently logged-in user's display name

  21. 21

    How to get the name of currently running app in an App for office 2013

  22. 22

    XMPPFramework - How to get currently logged-in user's display name

  23. 23

    How to get a list of unused kernel modules of currently running system? (Static and loaded)

  24. 24

    How to get the video file for a movie currently playing in browser?

  25. 25

    How to get the path to the currently included cmake file in a function?

  26. 26

    Intellij IDEA plugin how to get path of currently oppened file?

  27. 27

    How to get the video file for a movie currently playing in browser?

  28. 28

    Debian: How to get the current loaded kernel package name?

  29. 29

    Get path of currently marked file

HotTag

Archive