0

The issue is, I cannot seem to find a way to actually put the Logging gui before my app starts, FXMLseveral any ways I can put in the loging form I made with labels and method which required login informations before my application pops up?

I tried two ways, first by calling :

Parent root = FXMLLoader.load(getClass().getResource(

second one I created an :

AnchorPane pane = FXMLLoader.load(getClass().getResources())

third:

Parent root= (Parent)load.load();
Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31
  • Welcome to StackOverflow! Please take the [tour] and read [ask] a Good Question. Then, read how to create a [mcve] that demonstrates the problem you're having. Once that's all done, just [edit] your question to provide the code you have so far, what steps you've taken to fix your issue, and clarify your question. – Zephyr Jun 15 '19 at 14:17
  • Did you try to use a Preloader? https://docs.oracle.com/javafx/2/deployment/preloaders.htm – Miss Chanandler Bong Jun 15 '19 at 22:06

1 Answers1

0

Assuming that your Login.fxml is placed inside the package called com.example.login, you can make it to be the first fxml opened by Javafx application by doing the following:

public class Main extends Application {
    public static void main(String[] args) throws Exception 
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception{
      /*we make it the first fxml to be loaded. 
        Please note that you have to get the correct relative path to it or else 
        you will get 'location is required' error*/

        Parent root = FXMLLoader.load(this.getClass().getResource("/com/example/login/Login.fxml"));
        Scene scene = new Scene(root);
        Stage visibleStage = new Stage();
        visibleStage.initOwner(primaryStage);
        visibleStage.setTitle("My title");
        visibleStage.initStyle(StageStyle.DECORATED);
        visibleStage.setScene(scene);
        visibleStage.setOnHidden((e) -> {
            Platform.runLater(primaryStage::hide);
        });
        visibleStage.setOnCloseRequest(e -> System.exit(0));
        visibleStage.sizeToScene();
        visibleStage.show();
    }
}

I would also advise that you add some code to your question if you really want a very helping answer, for example, your Application class code like the one that I have provided.

Vinyl
  • 333
  • 1
  • 7