2012-02-11 45 views
3

編輯 我一直在尋找一個「ScrollPane」而不是ScrollBar。如何在javafx2中使用FXML創建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"/> 

一切正常。

我有我想要添加許多標籤..我想垂直框中有 「滾動」 的能力的垂直框因爲這些行被添加。

現在這就是我的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> 

但是,這給了我錯誤和編譯,將無法正常工作。我也嘗試刪除孩子。沒有運氣..任何想法?我發現很難找到在Javafx 2.0中做「FXML」的方法。使用代碼很容易...

回答

4

ScrollPane沒有財產children,它有content類型Node。下一個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> 
+3

人們會認爲'ScrollPane'是'Pane'的一個子類,但它不是。相反,層次結構(從Java 8起)是ScrollPane 2014-04-29 09:20:18

相關問題