2016-05-13 75 views
0

我在TabPane的選項卡中放置了一些內容,但TabPane的寬度在我看來等於選項卡內最長的元素(最長的元素在圖片上不可見)。JavaFX ScrollPane與TabView填充空間

的TabPane通過FXMLLoader.load(加載到一個ScrollPane),這就是爲什麼我希望它填滿了整個空間,裏面的最長元素的不只是規模..

enter image description here

我如何使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> 

回答

2
ScrollPane sp = new ScrollPane(); 
sp.setContent(tp); 
sp.setFitWidth(true); 
+0

謝謝!正確的方法名稱是sp.setFitToWidth(true);如果其他人正在尋找解決方案... – user1802693