Search code examples
javaeclipsejavafxfxmlscenebuilder

How can I import a layout from another package in JavaFX?


Here is the code:

            package application;
            //imports
            import javafx.application.Application;
            import javafx.fxml.FXMLLoader;
            import javafx.scene.Scene;
            import javafx.scene.layout.Pane;
            import javafx.stage.Stage;
            import application.view.*; //i've tried import the package, but i don't know if this is correct



            public class Main extends Application {
                @Override
                public void start(Stage primaryStage) {
                    try {

//here is my issue:

                        **Pane root = FXMLLoader.load(getClass().getResource("application.view.Lay.fxml"));**

                        Scene scene = new Scene(root,400,400);
                        primaryStage.setScene(scene);
                        primaryStage.show();
                    } catch(Exception e) {
                        e.printStackTrace();
                    }
                }

            }

I've Tried this, but it doesn't work, what am I doing wrong? Thanks for your time!


Solution

  • Try

    Pane root = FXMLLoader.load(getClass().getResource("/application/view/Lay.fxml"));