How to 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 perfectly.

I have a VBox in which I want to add MANY Labels. I would like VBox to be able to scroll as these lines are added.

Right now this is my FXML. Its in BorderPane .. However, I omitted the non-essential parts.

 <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 an error and compiles and will not work. I also tried to clean the children. No luck .. Any thoughts? It's hard for me to find a way to “FXML” do something in Javafx 2.0. Using the code is pretty simple ...

+4
source share
1 answer

ScrollPane does not have a children property, it has content type Node . The following 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
source

Source: https://habr.com/ru/post/1395942/


All Articles