繁体   English   中英

在 Mac 上调整 Window 的大小时 JavaFX 崩溃

[英]JavaFX crashes when resizing the Window on Mac

我正在使用带有最新版本 Java (FX)、macOS 以及 IntelliJ IDEA CE 的 Mac。 问题是,当我调整 JavaFX Window 的大小时,我的 Mac 立即崩溃。 只有当我按下电源按钮五秒钟时,MacBook 才会重新启动。 我用这些自动创建的文件创建了一个普通的 IntelliJ JavaFX 项目:

  • HelloController.java
  • HelloApplication.java
  • 你好-view.fxml

我没有改变任何东西并启动了程序。 一切正常,直到您尝试调整 window 的大小,Mac 崩溃,您无法移动 courser 或其他任何东西。

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

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

你好-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>

我对边框窗格(使用 Scene Builder 编辑)有同样的问题。

有人有同样的问题,或者知道解决这个问题的方法吗?

我刚刚在我的 Mac (macOS Catalina 10.15.7) 上运行了您的示例程序。 我可以毫无问题地让它变大变小。 我的 Java 配置是:

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

也许您应该将此初始化块添加到您的代码中,以确保您在运行时确实使用了您认为正在使用的版本。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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