在我的JavaFX程序中,我有一个标签,该标签被编码为在单击时打开一个新阶段。当我在IDE中执行程序时,新的阶段会很好地打开,但是当我以JAR格式启动程序时,它将不会显示。
这是标签的代码
l2.setOnMouseClicked(e -> {
signUp sign = new signUp();
stackPane.setEffect(new BoxBlur(3, 3, 3));
sign.signups().showAndWait();
stackPane.setEffect(new BoxBlur(0, 0, 0));
});
这是单击Label时返回阶段的函数代码。
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;
}
}