获取hbox / vbox中的节点位置

时间:2013-07-08 01:48:10

标签: javafx-2 javafx

我试图在控制器类中获取TextField的X,Y位置,我已将其与Label和ComboBox一起包装在hbox中。

我通常知道你可以通过拨打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>`

我甚至试过get addFieldName.getWidth()并且它也返回0.

1 个答案:

答案 0 :(得分:0)

Node的属性很少,可以让您了解其边界的详细信息。

getBoundsInLocal()getBoundsInParent();

请参阅getBoundsInLocal以供参考。

相关问题