gpt4 book ai didi

java - JavaFX 中的 ScrollPane 类缺少 getChildren 方法

转载 作者:行者123 更新时间:2023-12-01 18:03:36 25 4
gpt4 key购买 nike

当尝试使用以下代码时,发生异常 java.lang.UnsupportedOperationException:

ScrollPane scrollPaneIdFx = new ScrollPane();
ImageView imageViewIdFx = new ImageView();
scrollPaneIdFx.getChildrenUnmodifiable().add(imageViewIdFx);

如果尝试使用下面的代码,则由于 protected 说明符, getChildren 不可见

ScrollPane scrollPaneIdFx = new ScrollPane();
ImageView imageViewIdFx = new ImageView();
scrollPaneIdFx.getChildren().add(imageViewIdFx);

有人可以建议一下,如何将子项添加到 ScrollPane 中吗?

最佳答案

ScrollPane 将其单个子项存储在 contentProperty 中:

The node used as the content of this ScrollPane.

因此更正后的代码是:

scrollPaneIdFx.setContent(imageViewIdFx);

如果您想在 ScrollPane 中存储多个 Node,则应将 contentProperty 设置为容器之一(Parent 对象),那么应将 Node 添加到此容器中。

关于java - JavaFX 中的 ScrollPane 类缺少 getChildren 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38659713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com