0

In my JavaFX program, I have a Label that is coded to open a new stage on click. The new stage opens up just fine when I execute the program in IDE but the it just won't show up when I launch the program in JAR Format.

Here's the code for the Label

    l2.setOnMouseClicked(e -> {
        signUp sign = new signUp();
        stackPane.setEffect(new BoxBlur(3, 3, 3));
        sign.signups().showAndWait();
        stackPane.setEffect(new BoxBlur(0, 0, 0));

    });

Here's the code for the function that returns the stage when the Label is clicked.

     public Class signUp{
    Scene scene;
     public Stage signups() {
    Stage stage = new Stage();

    stackPane = new StackPane();
    GridPane gridPane = new GridPane();
    gridPane.setStyle("-fx-background-color:white;" + "-fx-effect:dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 0);" + "-fx-background-radius:10;");
    gridPane.setMaxSize(280, 350);
    gridPane.setPadding(new Insets(10));


    gridPane.setHgap(10);
    gridPane.setVgap(10);
    stackPane1 = new StackPane();
    BackgroundImage bg = new BackgroundImage(new Image("bread.jpg", 960, 540, false, true),
            BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
            BackgroundSize.DEFAULT);
    stackPane1.setBackground(new Background(bg));

    double x = 20;

    username = new JFXTextField();
    username.setPromptText("Username");
    password = new JFXPasswordField();
    password.setPromptText("Password");
    password1 = new JFXPasswordField();
    password1.setPromptText("Re-type Password");
    username.setMinWidth(220);
    password.setMinWidth(220);
    password1.setMinWidth(220);


    JFXButton sign_up = new JFXButton("Sign Up");
    sign_up.setTextFill(Color.WHITE);
    sign_up.setStyle("-fx-background-color:#2196F3");
    sign_up.setMinSize(220, 30);
    sign_up.setOnMouseEntered(e->{
        scene.setCursor(Cursor.HAND);
    });
    sign_up.setOnMouseExited(e->{
        scene.setCursor(Cursor.DEFAULT);
    });


    agreement = new JFXCheckBox("I accept the Terms & Conditions");

    ImageView logo = new ImageView(new Image("logo.png"));
    logo.setFitWidth(200);
    logo.setFitHeight(130);

    gridPane.add(logo, 1, 0);

    gridPane.add(username, 0, 1, 3, 1);
    gridPane.add(password, 0, 2, 3, 1);
    gridPane.add(password1, 0, 3, 3, 1);
    gridPane.add(agreement, 0, 4, 3, 1);
    gridPane.add(sign_up, 0, 5, 3, 1);
    gridPane.setAlignment(Pos.CENTER);
    gridPane.setHalignment(sign_up, HPos.LEFT);
    gridPane.setHalignment(username, HPos.CENTER);
    gridPane.setHalignment(password, HPos.CENTER);
    gridPane.setHalignment(password1, HPos.CENTER);
    gridPane.setHalignment(logo, HPos.CENTER);
    gridPane.setValignment(sign_up, VPos.BOTTOM);


    stackPane.setAlignment(Pos.CENTER);


    stackPane1.getChildren().add(gridPane);
    stackPane.getChildren().add(stackPane1);
    scene = new Scene(stackPane, 380, 400);
    stage.setScene(scene);
    stage.setTitle("Sign Up");
    stage.initModality(Modality.APPLICATION_MODAL);


    return stage;


}
    }
Steven
  • 1
  • 1
  • Maybe dependencies are resolved by your IDE and missing in your jar ? – Paul May 12 '19 at 12:18
  • @Paul.F-G Could you elaborate more on that please ? I'm quite new in Java .... Thanks – Steven May 12 '19 at 12:24
  • What IDE are you using? What is your project structure? How do you build your project? – Paul May 12 '19 at 12:27
  • @Paul.F-G I'm using Intellij and I followed this to build my project. https://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly The program launches in JAR format just fine with my main menu and everything but the new stage just won't show when I click the label. – Steven May 12 '19 at 12:31
  • Run your JAR from the command line to see if you get any errors. – Slaw May 12 '19 at 12:53
  • 1
    @Slaw Thank you so much!!!! I finally solved my problem ! I mistyped the name of a image file so instead of "Logo.png", I typed "logo.png". And also now only I know file name is case-insensitive in the IDE but is not in the JAR format. – Steven May 12 '19 at 13:05

0 Answers0