java fx切换面板,在Java FX中切换场景时如何保持窗口大小?

I've simply been trying to make sense of why the window size (which I set to full screen) is changing when I change scenes, is there a way (i.e. a command) which can be issued once to let Java FX know not to change the size?

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();

}

}

解决方案

I'like do blow:

StackPane layout = new StackPane();

layout.getChildren().add(exit_pro);

layout.getChildren().add(back_to_start);

start.setOnAction(e -> {

back_to_start.toFront();

exit_pro.setVisible(false);

});

back_to_start.setOnAction(e -> {

exit_pro.toFront();

back_to_start.setVisible(false);

});

Switch StackPane's children to act like switch two scenes.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值