如何在Java FXML

时间:2018-05-06 20:08:13

标签: java fxml

如果我问过可能不适用于java fx的愚蠢问题,我很抱歉。

我有以下fxml文件

<AnchorPane  maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="294.0" prefWidth="354.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Button fx:id="cancel" layoutX="199.0" layoutY="149.0" mnemonicParsing="false" text="Cancel" />
      <Button id="ok" fx:id="ok" layoutX="259.0" layoutY="149.0" mnemonicParsing="false" text="OK" />
      <TextField fx:id="field" layoutX="62.0" layoutY="120.0" prefHeight="26.0" prefWidth="229.0" />
   </children>
</AnchorPane>

现在我要加载该文件。所以我想尝试以下方法。

Node parent = FXMLLoader.load(getClass().getResource("../layout/dialog.fxml"));
Button ok = (Button) parent.lookup("#id");

这里实际上我想通过使用lookUp方法访问ok按钮。但它说 ok 按钮为空。

  

注意:我不想通过使用控制器属性fx:controller或@FXML注释来执行此操作。

有没有办法可以这样做?

0 个答案:

没有答案
相关问题