Making a borderless JAVAFX Window Movable

Bothered by default FXML window outline? Maybe you want to create you own custom Minimize, Maximize and Close buttons like above. It’s easy. First you need to remove the defaults.

Step 1

Go to your Main class of your project and set your stage to be UNDERDECORATED or TRANSPARENT.


Step 2

The next thing you want to do is initialize two doubles for the x and y screen offsets;

private double xOffset = 0; 
private double yOffset = 0;

Step 3

Add mouse events to your root, i.e your FXML loader and you are ready to “move”

root.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
stage.setX(event.getScreenX() - xOffset);
stage.setY(event.getScreenY() - yOffset);

Final class will look like:

That is it for now.

Check my youtube channel for more of JavaFX.