Center stage on parent stage

You can use the parent stage’s X/Y/width/height properties to do that. Rather than using Stage#centerOnScreen, you could do the following: public class CenterStage extends Application { @Override public void start(final Stage stage) throws Exception { stage.setX(300); stage.setWidth(800); stage.setHeight(400); stage.show(); final Stage childStage = new Stage(); childStage.setWidth(200); childStage.setHeight(200); childStage.setX(stage.getX() + stage.getWidth() / 2 – childStage.getWidth() / … Read more

JavaFX Single Instance Application

This is based upon the solution in the blog post: Java Single Instance Application. The solution uses the “Socket Technique”: With this technique we start listening on a port, only one process can listen on a socket so after first instance of our application binds itself to the socket other instances will get BindException, which … Read more

Moving an undecorated stage in javafx 2

I created a sample of an animated clock in an undecorated window which you can drag around. Relevant code from the sample is: // allow the clock background to be used to drag the clock around. final Delta dragDelta = new Delta(); layout.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { // record a delta … Read more

JavaFX Application Icon

Assuming your stage is “stage” and the file is on the filesystem: stage.getIcons().add(new Image(“file:icon.png”)); As per the comment below, if it’s wrapped in a containing jar you’ll need to use the following approach instead: stage.getIcons().add(new Image(<yourclassname>.class.getResourceAsStream(“icon.png”)));

How to get stage from controller during initialization?

You can get the instance of the controller from the FXMLLoader after initialization via getController(), but you need to instantiate an FXMLLoader instead of using the static methods then. I’d pass the stage after calling load() directly to the controller afterwards: FXMLLoader loader = new FXMLLoader(getClass().getResource(“MyGui.fxml”)); Parent root = (Parent)loader.load(); MyController controller = (MyController)loader.getController(); controller.setStageAndSetupListeners(stage); … Read more

JavaFX Location is not set error message [duplicate]

I had this problem and found this post. My issue was just a file name issue. FXMLLoader(getClass().getResource(“/com/companyname/reports/” + report.getClass().getCanonicalName().substring(18).replaceAll(“Controller”, “”) + “.fxml”)); Parent root = (Parent) loader.load(); I have an xml that this is all coming from and I have made sure that my class is the same as the fxml file less the word … Read more