2015-09-29 1630 views
2

的寬度在我fxml文件的根元素看起來是這樣的:FXML prefHeight和prefWidth VS高度和場景

<SplitPane dividerPositions="0.5" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.AbweichungenKonfigurationController"> 
    ... 
</SplitPane> 

和調用FXML文件中的類看起來像這樣:

現在,在FXML文件中定義的大小:

prefHeight="600.0" prefWidth="900.0" 

由場景尺寸覆蓋:

primaryStage.setScene(new Scene(root, 1000, 800)); 

出現的窗口的大小在場景的構造函數中定義!

是否有機會使用fxml文件中定義的大小?或者我應該如何處理這個問題?

回答

0

Scene將強制其根目錄的大小爲Scene,而不考慮其最小/最大/最大大小。

嘗試用StackPane包裝SplitPaneStackPane沒有大小限制。 StackPane將尊重SplitPane的首選尺寸:

<StackPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.AbweichungenKonfigurationController"> 

    <SplitPane dividerPositions="0.5" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="900.0" > 
     ... 
    </SplitPane> 

</StackPane> 
相關問題