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