Ich dachte an sowas
[code=Java]package fxmlloader;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class FxmlLoaderTest extends Application {
@Override public void start(Stage stage) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
Parent root = loader.load();
MyController ctrl = loader.getController();
ctrl.handleButtonAction();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] parameters) {
launch(parameters);
}
}
[/code]
[code]<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.111" fx:controller="fxmlloader.MyController">
<children>
<Button fx:id="button" layoutX="126" layoutY="90" onAction="#handleButtonAction" text="Click Me!" />
<Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
</children>
</AnchorPane>[/code]
[code=Java]package fxmlloader;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class MyController {
private int counter;
@FXML
Button button;
@FXML
Label label;
public void handleButtonAction() {
label.setText("clicked " + ++counter);
}
}[/code]