简体   繁体   English

JavaFX网格窗格和内容大小

[英]JavaFX Grid Pane and content size

I've been trying to get a GridPane's content to behave regarding auto-size but I'm relatively new to JavaFX, so I've not had any success. 我一直在尝试使GridPane的内容在自动调整大小方面起作用,但是我对JavaFX还是比较陌生,所以我没有取得任何成功。 Basically, each column is what appears to me to be a completely random size, and I have no idea how to make them grow correctly. 基本上,每列对我来说都是完全随机的大小,我不知道如何使它们正确增长。 If I try to set column constraints, the content sometimes disappears completely, sometimes it's just sized completely arbitrarily. 如果我尝试设置列约束,则内容有时会完全消失,有时会完全随意调整大小。 Trying to bind preferred width to anything else also fails to work. 尝试将首选宽度绑定到其他任何内容也无法正常工作。 I'm sure the error is mine, though. 我确定错误是我的,但是。 Here's my code (the contentHolder is a ScrollPane with vGrow set to ALWAYS): 这是我的代码(contentHolder是将vGrow设置为ALWAYS的ScrollPane):

    int row = 1;
    GridPane gridPane = new GridPane();
    for (List<IndexObject> stepList : search) {
        Label itemLabel = new Label();
        itemLabel.setText(String.valueOf(row));

        TreeItem<String> treeRoot = new TreeItem<>(stepList.get(0).getPath());
        for (int line = 1; line < stepList.size(); line++) {
            treeRoot.getChildren().add(new TreeItem<>(stepList.get(line).getPath()));
        }
        TreeView treeView = new TreeView();
        treeView.setShowRoot(true);
        treeView.setRoot(treeRoot);
        treeRoot.setExpanded(true);

        IndexObject lastObject = stepList.get(stepList.size() - 1);

        TextArea output = new TextArea();
        output.setText(lastObject.prettyPrint());

        gridPane.addRow(row, itemLabel, treeView, output);
        row++;
    }
    contentHolder.setContent(gridPane);

Everything up to the contentHolder is defined in fxml. 直到contentHolder的所有内容都在fxml中定义。 Here's what it looks like. 这是它的样子。 No entry has anywhere near the height that is automatically assigned, but all the widths are too small. 自动分配的高度附近没有条目,但是所有宽度都太小。 What am I missing? 我想念什么?

格式化失败

The answer is that the scroll pane does not automatically resize until you make it: 答案是滚动窗格在您进行滚动之前不会自动调整大小:

<ScrollPane VBox.vgrow="ALWAYS" fitToWidth="true">

at which point everything works as expected. 在这一点上一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM