2
我正在使用Javafx(不使用FXML),並且我將舞臺傳遞給控制器,以在單擊按鈕時更改舞臺上的場景。場景變化正確,但舞臺和場景的大小增加。它的大小增加約0.1(寬度),高度有時也增加(不是每次)。Javafx場景切換導致舞臺大小增加
這是使用的控制器。
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);
}
} 我相信這是與我擦肩而過的階段,任何指針將不勝感激。
創建一個新的舞臺。 – Sedrick
如果我創建一個新的階段,窗口關閉並重新打開片刻。這不是我要去的簡化的設計。 – user2370794
我的猜測是組件不適合舞臺原始尺寸。我認爲這會導致舞臺增長以適應新的組件。 – Sedrick