我只是试图弄清楚当我改变场景时为什么窗口大小(我设置为全屏)正在改变,是否有一种方法(即一个命令)可以发出一次让
Java FX知道不要改变大小?
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
Scene scene,scene_2;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage Win_primary) throws Exception {
Win_primary.setTitle("AN-0");
Button start,exit_pro,back_to_start;
start= new Button();
start.setText("Start");
Image exit_door = new Image("file:C:\\Users\\MyPc\\Pictures\\FX\\vector-icons_05-128 (2).png");
exit_pro= new Button ();
exit_pro.setGraphic(new ImageView(exit_door));
start.setStyle(
"-fx-background-radius: 100em; " +
"-fx-min-width: 200px; " +
"-fx-min-height: 200px; " +
"-fx-max-width: 200px; " +
"-fx-max-height: 170px;" +
"-fx-font-size: 20px"
);
exit_pro.setMaxSize(50, 50);
exit_pro.setOnAction(e -> Win_primary.close());
StackPane layout = new StackPane();
layout.setStyle("-fx-background-color: #FFFFFF ;");
layout.getChildren().add(start);
layout.setAlignment(exit_pro, Pos.BOTTOM_CENTER);
layout.getChildren().add(exit_pro);
start.setOnAction(e -> {
Win_primary.setScene(scene_2);
});
scene = new Scene(layout, 300, 250);
//scene 2
StackPane layout2 = new StackPane();
back_to_start = new Button("Cancel");
layout2.setStyle("-fx-background-color: #FFFFFF ;");
layout2.getChildren().add(back_to_start);
layout.setAlignment(back_to_start, Pos.BOTTOM_CENTER);
scene_2 = new Scene (layout2,300,250);
back_to_start.setOnAction(e -> Win_primary.setScene(scene));
Win_primary.setScene(scene);
Win_primary.setMinHeight(700);
Win_primary.setMinWidth(700);
Win_primary.setMaximized(true);
Win_primary.setFullScreen(true);
Win_primary.show();
}
}