【发布时间】:2019-11-07 11:09:09
【问题描述】:
我想将内部类“FinishDialogController”控制器绑定到 FXML。 这是一个真正的难题。
但是fx:controller="app.view.MainLayoutController.FinishDialogController" 是错误的。
谁知道正确的方法?
我在Introduction to FXML 中搜索“inner”,但没有找到。
这是完整的 FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="108.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.view.MainLayoutController.FinishDialogController">
<children>
<TextField fx:id="textField" layoutX="25.0" layoutY="50.0" onAction="#handleTextField" prefHeight="23.0" prefWidth="314.0" AnchorPane.leftAnchor="25.0" AnchorPane.rightAnchor="25.0" />
<Button fx:id="okButton" layoutX="219.0" layoutY="78.0" mnemonicParsing="false" onAction="#handleOkButton" text="OK" />
<Button fx:id="deleteButton" layoutX="271.0" layoutY="78.0" mnemonicParsing="false" onAction="#handleDeleteButton" text="Delete" />
</children>
</AnchorPane>
【问题讨论】:
-
尝试使用 $ 作为分隔符
app.view.MainLayoutController$FinishDialogController。 -
@mr mcwolf 感谢您的回复。听起来是个好主意,但它并没有解决我的问题。
-
你的内班是
static吗?非static内部类不能在没有controllerFactory的情况下由FXMLLoader初始化,因为它们的构造函数在参数列表的开头有一个隐藏的附加参数:封闭类的实例。是public吗?FXMLLoader不会初始化任何非public类。 -
@fabian 谢谢你的回复,我的问题已经解决了。
标签: java javafx fxml fxmlloader