【发布时间】:2016-12-07 13:59:28
【问题描述】:
我正在使用 Javafx(不使用 FXML),并且我正在将舞台传递给控制器以在单击按钮时更改舞台上的场景。场景变化正确,但舞台和场景的大小增加了。它的大小增加了大约 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);
}
} 我相信这与我的舞台传递有关,任何指点将不胜感激。
【问题讨论】:
-
创建一个新阶段。
-
如果我创建一个新阶段,窗口会关闭并重新打开片刻。这不是我想要的流线型设计。
-
我的猜测是组件不适合舞台原始尺寸。我认为这会导致舞台变大以适应新的组件。
-
我以为可能是这样,但是新场景和上一个场景一样,只是我改变了背景颜色(所以我可以区分它们)。
-
替换现有场景的根目录,而不是替换场景。
标签: java javafx scene stage sizing