I'm trying to make a confirmation box in JavaFX like in this video, but I want to load it from FXML because it is easier. The main method is supposed to call ask().
public class Controller {
@FXML
Label confirmLabel;
}
public class ConfirmBox {
public static Stage confirmStage;
public static boolean answer;
private static final int WIDTH = 200;
private static final int HEIGHT = 141;
public static boolean ask(String title, String question) throws IOException {
confirmStage = new Stage();
confirmStage.initModality(Modality.APPLICATION_MODAL);
AnchorPane confirmPane = (AnchorPane) FXMLLoader.load(ConfirmBox.class.getResource("ConfirmBox.fxml"));
ERROR > Controller.confirmLabel.setText(question);
Scene confirmScene = new Scene(confirmPane);
confirmStage.setScene(confirmScene);
confirmStage.showAndWait();
return answer;
}
}
Instead of opening the window, it gives tells me
Cannot make a static reference to the non-static field Controller.confirmLabel
How can I make it work?