JavaFX crashes when resizing the Window on Mac

Viewed 176

I am using a Mac with the latest version of Java (FX), macOS as well as IntelliJ IDEA CE. The problem is that when I resize a JavaFX Window, my Mac crashes instantly. Only when I press the power button for five seconds, the MacBook restarts. I created a normal IntelliJ JavaFX Project, with these automatically created files:

  • HelloController.java
  • HelloApplication.java
  • hello-view.fxml

I didn't change anything and started the program. Everything works fine until you try to resize the window, the Mac crashes, you can not move the courser or anything else.

HelloApplication.java:

package com.example.demo;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 320, 240);
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();
}

    public static void main(String[] args) {
        launch();
    }
}

Hello Controller.java:

package com.example.demo;

import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class HelloController {
    @FXML
    private Label welcomeText;

    @FXML
    protected void onHelloButtonClick() {
        welcomeText.setText("Welcome to JavaFX Application!");
    }
}

hello-view.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>


<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
   <bottom>
      <Button mnemonicParsing="false" text="Button" BorderPane.alignment="CENTER" />
   </bottom>
</BorderPane>

I have the same issue with the Border Pane (edited with Scene Builder).

My Hardware:

  • MacBook Pro Mid 2012
  • Dual-Core Intel Core i5 2.5 GHz
  • 16GB 1600 MHz
  • DDR3 1TB Samsung EVO 860 SSD
  • Intel HD Graphics 4000 1536 MB
  • macOS Catalina 10.15.7

Java (FX) Version:

I tried:

java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.runtime.version: 17.0.1+12-LTS-39
javafx.runtime.version: 17.0.1+1

And:

java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.runtime.version: 17.0.1+12-LTS-39
javafx.runtime.version: 18-ea+8

Does someone have the same issue, or know a way to fix this?

1 Answers

I just ran your example program on my Mac (macOS Catalina 10.15.7). I could make it bigger and smaller without any problem. My Java configuration was:

java.vm.name: OpenJDK 64-Bit Server VM
java.runtime.version: 18-ea+29-2007
javafx.runtime.version: 18-ea+8

Maybe you should add this init block to your code to make sure that you are really using the version at run-time that you think you are using.

@Override
public void init() {
    System.out.format("java.vm.name: %s\n", System.getProperty("java.vm.name", "(undefined)"));       
    System.out.format("java.runtime.version: %s\n", System.getProperty("java.runtime.version", "(undefined)"));
    System.out.format("javafx.runtime.version: %s\n", System.getProperty("javafx.runtime.version", "(undefined)"));        
}
Related