简体   繁体   中英

JavaFX crashes when resizing the Window on Mac

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).

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

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)"));        
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM