2013-07-08 29 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