Tag: fxml

使用Kotlin时,FXML控件始终为空

使用IntelliJ我创建了一个JavaFX应用程序,然后将Kotlin和Maven作为框架添加到它。 它带有一个sample.fxml文件和一个Controller.java和Main.java。 我在Kotlin(MainWindowController.kt)中为控制器创建了一个新类,并将sample.fxml文件重命名为MainWindow.fxml。 我更新了MainWindow.fxml,如下所示: 在我的MainWindowController.kt文件中,我有: package reader import javafx.fxml.FXML import javafx.scene.control.Label class MainWindowController { @FXML var helloLabel: Label? = null init { println(“Label is null? ${helloLabel == null}”) } } 这是我的Main.java: import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getClassLoader().getResource(“MainWindow.fxml”)); primaryStage.setTitle(“My App”); primaryStage.setScene(new Scene(root, 1000, […]