0
我在TabPane的選項卡中放置了一些內容,但TabPane的寬度在我看來等於選項卡內最長的元素(最長的元素在圖片上不可見)。JavaFX ScrollPane與TabView填充空間
的TabPane通過FXMLLoader.load(加載到一個ScrollPane),這就是爲什麼我希望它填滿了整個空間,裏面的最長元素的不只是規模..
我如何使TabPane填充所有可用空間?
裝載機:
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("View.fxml"));
Node tp = loader.load();
ScrollPane sp = new ScrollPane();
sp.setContent(tp);
primaryStage.setScene(new Scene(sp, 300, 200));
primaryStage.show();
View.fxml:
<TabPane tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<tabs>
<Tab text="Untitled Tab 1">
<content>
<AnchorPane />
</content>
</Tab>
<Tab text="Untitled Tab 2">
<content>
<AnchorPane />
</content>
</Tab>
</tabs>
</TabPane>
謝謝!正確的方法名稱是sp.setFitToWidth(true);如果其他人正在尋找解決方案... – user1802693