I'm using JavaFX11. Both this and this works with a small change. Here is my working example. I'm using rgielen's javafx-weaver
Main:
package com.featuriz.controller;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import net.rgielen.fxweaver.core.FxControllerAndView;
import net.rgielen.fxweaver.core.FxmlView;
import org.springframework.stereotype.Component;
@Component
@FxmlView("/com/featuriz/ui/Login.fxml")
public class LoginController {
private final FxControllerAndView<InfoDialogController, AnchorPane> infoDialog;
@FXML
private Text featuriz;
public LoginController(FxControllerAndView<InfoDialogController, AnchorPane> infoDialog) {
this.infoDialog = infoDialog;
}
@FXML
public void initialize() {
featuriz.setOnMouseClicked(
actionEvent -> this.infoDialog.getController().show()
);
}
}
Dialog:
package com.featuriz.controller;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import net.rgielen.fxweaver.core.FxmlView;
import org.springframework.stereotype.Component;
@Component
@FxmlView("/com/featuriz/ui/InfoDialog.fxml")
public class InfoDialogController {
private Stage stage;
@FXML
private Label lbl_info;
@FXML
private Button closeButton;
@FXML
private AnchorPane dialog_info;
@FXML
public void initialize() {
Scene scene = new Scene(dialog_info);
scene.setFill(Color.TRANSPARENT);
this.stage = new Stage();
this.stage.initModality(Modality.APPLICATION_MODAL);
this.stage.initStyle(StageStyle.TRANSPARENT);
this.stage.setScene(scene);
this.stage.setAlwaysOnTop(true);
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
lbl_info.setText("JavaFX " + javafxVersion + "\nRunning on Java " + javaVersion + ".");
closeButton.setOnAction(
actionEvent -> this.stage.close()
);
}
public void show() {
this.stage.show();
}
}