ril3y
ril3y

Reputation: 952

How do you create a ScrollBar using FXML in javafx2?

EDIT I was looking for a "ScrollPane" not a 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"/>

Everything works just fine.

I have a VBox that I want to add MANY Labels to.. I would like the VBox to have the ability to "scroll" as these lines are added.

Right now this is what my FXML looks like. Its in a BorderPane.. However I have omitted the irrelevant portions.

<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>

However this gives me error and compile and will not work. I have tried to remove children as well. No luck.. Any thoughts? I find it hard to find the "FXML" way to do things in Javafx 2.0. Using code is pretty easy...

Upvotes: 5

Views: 13317

Answers (1)

Sergey Grinev
Sergey Grinev

Reputation: 34478

ScrollPane doesn't have property children, it has content of type Node. Next fxml will work for you:

<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>

Upvotes: 7

Related Questions