编辑 我一直在寻找“ScrollPane”而不是 ScrollBar。
<ScrollPane fitToWidth="true" fx:id="sasd">
<content>
<VBox prefWidth="200" alignment="center" fx:id="Left">
<children>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
一切正常。
我有一个 VBox,我想向其中添加许多标签。我希望 VBox 在添加这些行时能够“滚动”。
现在这就是我的 FXML 的样子。它在 BorderPane 中。但是我省略了不相关的部分。
<left>
<VBox prefWidth="200" alignment="center" fx:id="Left">
<children>
<ScrollBar orientation="VERTICAL" fx:id="sasd">
<children>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x121 y13 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x10 y113 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x121 y13 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x10 y113 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
</children>
</ScrollBar>
</children>
</VBox>
但是这给我错误和编译并且不会工作。我也试图移除 child 。没有运气..有什么想法吗?我发现很难找到在 Javafx 2.0 中做事的“FXML”方式。使用代码非常简单...
最佳答案
ScrollPane
没有属性 children
,它有类型为 Node
的 content
。下一个 fxml 将为您工作:
<ScrollPane fx:id="sasd">
<content>
<VBox prefWidth="200" alignment="center" fx:id="Left">
<children>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x121 y13 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x10 y113 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x121 y13 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x10 y113 z23"/>
<Label alignment="center" fx:id="gcProgramLine" text="g0x100 y123 z23"/>
</children>
</VBox>
</content>
</ScrollPane>
关于java - 如何在 javafx2 中使用 FXML 创建滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9242606/