How do you create a ScrollBar using FXML in javafx2?


Question

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

1
4
2/25/2012 9:34:34 PM

Accepted Answer

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>
4
2/13/2012 1:51:01 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon