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,以及。
你有没有解决这个问题。我陷入了同样的问题。布局,boundinparent,不起作用。 – user43968