我试图让X,在控制类一个TextField我有一个标签,和ComboBox一起包裹在一个盒子里的Y位置。
我通常知道你可以通过调用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为好。