我正在使用Javafx(未使用FXML),在单击按钮时将stage传递给控制器以更改舞台上的场景。场景正确更改,但舞台和场景的大小增加了。它的宽度大约增加了0.1,高度有时也增加(不是每次都增加)。
以下是使用的控制器:
以下是使用的控制器:
public class Controller {
public Controller(){
}
public static void homeButtonhandler(Stage stage){
stage.close();
}
public static void adminButtonhandler(Stage stage){
adminPane adminPane1 = new adminPane(stage);
Scene adminScene = new Scene (adminPane1);
stage.setScene(adminScene);
}}
adminPane扩展了我创建的另一个类mainPane,两者都扩展了Pane类。它们内部还有其他面板来创建GUI结构。主面板的大小设置如下:
top = createTop(stage);
this.getChildren().addAll(top);
this.setWidth(stage.getWidth());
this.setPrefWidth(stage.getWidth());
this.setMaxWidth(stage.getWidth());
this.setMinWidth(stage.getWidth());
this.setHeight(stage.getHeight());
this.setMaxHeight(stage.getHeight());
this.setMinHeight(stage.getHeight());
this.setPrefHeight(stage.getHeight());
我正在使用以下方式测试类:
public class test extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
//primaryStage.setResizable(true);
mainPane myPane = new mainPane(primaryStage);
Scene homeScene = new Scene (myPane);
primaryStage.setScene(homeScene);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/resources/icons/joulesIcon.png")));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
我相信这与我通过阶段有关,非常感谢您提供的任何指导。
scene.setRoot(newNode)
- jewelsea