1

我将 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 左侧的所有可用空间?

谢谢!

4

1 回答 1

2

尝试这个

scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
于 2013-10-01T12:59:40.030 回答