java - 如何在 javafx2 中使用 FXML 创建滚动条?

标签 java user-interface javafx fxml

编辑 我一直在寻找“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,它有类型为 Nodecontent。下一个 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/

相关文章:

c++ - Qt 向导后退按钮 Ui 问题

css - JavaFX 组合框 CSS 样式

netbeans - 使用 JavaFX Scene Builder 2.0 同时显示两个窗口

java - Reverse Integer leetcode -- 如何处理溢出

java - 为什么我在这里得到不同的结果?

java - 将数字排列成 3 维数组的最快方法是什么?

java - 如何在运行时刷新 JPanel?

javascript - 生成基于 Web 的 GUI 以拖放组件并连接它们

java - 在 JavaFX 2.0 中将标签置于节点的中心

java - 使用 Spring Boot 拦截 SAML Http 请求