Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Java help - JavaFx Popup window Illegal state

Joined
Feb 9, 2019
Messages
44
I am trying to create a popup window to do configuration within my bot for a task-based system.

At this stage my main embedded javafx window is working 100%. Though I believe I am having pathing issues among other things when it comes to my secondary window. I have it that on button click, a window should popup, do a configuration, then pass the information back to the main class.

My code looks like:
Code:
    public static void runLater(Runnable runnable) {
        if (Platform.isFxApplicationThread()) {
            runnable.run();
        }
        else {
            Platform.runLater(runnable);
        }
    }
////////////////////////////////////
// later on
configButton.setOnAction((event) -> {
                    runLater(() -> {
                        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("com/lb25/gremlin/ui/config.fxml"));
                        try {
                            fxmlLoader.load();
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                    });
                });
and I get the error:
Code:
java.lang.IllegalStateException: Location is not set.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
which is specifically on fxmlLoader.load() line. This is the same directory that contains my main_ui.fxml. I also have both using the same pathing systems, both exist in my bin dir and both in my manifest.xml as resources. I think it comes down to my lack of understanding of how these ui's are created.

Any help would be awesome!
 
Joined
Feb 9, 2019
Messages
44
Sorry for my response here. But could you please direct me to an example of how this is done. I would do the searching myself but I am unsure of the terminology I am looking for. The ResourceManager search keeps returning examples of code similar to below.

I tried:

Code:
                        FXMLLoader fxmlLoader = new FXMLLoader();
                        try {
                            InputStream in = gremlin.class.getResourceAsStream("com/lb25/gremlin/ui/config.fxml");
                            InputStream in2 = ResourceManager.class.getResourceAsStream("com/lb25/gremlin/ui/config.fxml");
                            fxmlLoader.load(in2);
                        }
                        catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }

Trying input stream 'in' and 'in2'. Though both return null.
 
Arrr I found it. This solved it:
How to reference javafx fxml files in resource folder?

I had to reference a directory based a on an existing class. Then build off that path.

Code:
                configButton.setOnAction((event) -> {
                    runLater(() -> {
                        FXMLLoader fxmlLoader = new FXMLLoader();
                        try {
                            InputStream in = gremlin.class.getResourceAsStream("ui/config.fxml");

                            Parent root = fxmlLoader.load(in);
                            Stage stage = new Stage();
                            stage.setTitle("My New Stage Title");
                            stage.setScene(new Scene(root, 450, 450));
                            stage.show();
                        }
                        catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                    });
                });
 
Top