我将TreeView放置为ScrollPane的内容。 ScrollPane放置在SplitPane内部。
当我拖动SplitPane的分隔线使其大于TreeView的大小时,我看到TreeView的边框。
我希望在拖动SplitPane的分隔线后,调整TreeView的大小,使其与可用空间一样大。我的代码:
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(my TreeConnections)应该占用SplitPane左部分的所有可用空间?
谢谢!
最佳答案
尝试这个
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);