2013-09-30 33 views
1

我將TreeView放置爲ScrollPane的內容。 ScrollPane放置在SplitPane中。 當我拖動SplitPane的分隔線,使其變得比TreeView大小更大時,我會看到TreeView的邊框。 我希望TreeView能夠在拖動SplitPane的分隔符後調整空間大小。我的代碼:如何使TreeView的調整大小與父ScrollPane一樣多?

SplitPane splitPane = new SplitPane(); 
splitPane.getItems().addAll(createTreeOfConnections()); 

private ScrollPane createTreeOfConnections() { 
ScrollPane scrollPane = new ScrollPane(); 
scrollPane.setMinSize(100, 300); 
scrollPane.setPrefSize(200, 500); 
    scrollPane.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); 
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED); 
scrollPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED); 
scrollPane.setContent(new ConnectionsTree(this)); 
return scrollPane; 

類ConnectionsTree擴展TreeView和它的構造是:

public ConnectionsTree(MainStage mainStage) { 
     // here we set the root of ConnectionsTree which is not visible 
     super(); 
     this.mainStage = mainStage; 

     root = new ConnectionTreeItem(); 
     root.setExpanded(true); 
     super.setRoot(root); 
     super.setShowRoot(false); 
     super.setEditable(false); 
     super.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); 
     super.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); 

     retrieveExistentConnectionsNodes(); 
     ContextMenu contextMenu = new ContextMenu(createNewConnectionMenuItem(
       "New Connection", KeyCombination.valueOf("Ctrl+N"))); 
     super.setContextMenu(contextMenu);    } 

如何判斷TreeView控件(我TreeConnections),它應該採取SplitPane的左邊部分的所有可用空間?

謝謝!

回答

2

試試這個

scrollPane.setFitToHeight(true); 
scrollPane.setFitToWidth(true); 
+3

問題是,我把樹視圖到滾動窗格。但是TreeView在內部有scrollPane,在需要時顯示。將TreeView放入SplitPane後,它工作正常。 –

+0

@VolodymyrLevytskyi謝謝!我也解決了它。 –

相關問題