2013-07-08 26 views
0

我試圖獲取控制器類中的TextField的X,Y位置我已經將它包裝在一個hbox以及一個Label和ComboBox中。獲取節點在hbox/vbox中的位置

我通常知道你可以通過調用layoutX()layoutY()獲得X,Y但它返回0。

這裏是FXML代碼

<HBox alignment="CENTER_LEFT" padding="$x1" prefHeight="-1.0" prefWidth="-1.0" spacing="10.0"> 
    <children> 
     <Label maxWidth="-Infinity" minWidth="-Infinity" prefWidth="105.0" text="Add a Field:" /> 
     <TextField fx:id="addFieldName" prefWidth="200.0" promptText="Field Name" /> 
     <ComboBox fx:id="addFieldTypeComboBox" prefWidth="180.0" promptText="Choose a field type..."> 
      <items> 
      <FXCollections fx:factory="observableArrayList"> 
       <String fx:value="Item 1" /> 
       <String fx:value="Item 2" /> 
       <String fx:value="Item 3" /> 
      </FXCollections> 
      </items> 
     </ComboBox> 
     <Button fx:id="addFieldButton" mnemonicParsing="false" onAction="#handleAddFieldButtonAction" text="Add" /> 
    </children> 
</HBox>` 

我甚至嘗試得到addFieldName.getWidth()並返回0,以及。

+0

你有沒有解決這個問題。我陷入了同樣的問題。佈局,boundinparent,不起作用。 – user43968

回答

0

有幾個Node的屬性可以讓你得到它的界限的細節。

like getBoundsInLocal() and getBoundsInParent();

查看getBoundsInLocal僅供參考。

+0

我已經嘗試過,所有的屬性都是0。 – francisOpt