JavaFX: Global Menu of Javafx applications unresponsive on MACOS 10.15 Catalina before switching applications

Axel :

When I start the application, the global menu shows but cannot be accessed by either mouse nor keyboard. The app itself works and is responsive. When I switch to another application and then back again, everything works as expected.

It seems not not relevant if the application provides any menu on its own since the same problem occurs with the standard "Java" application menu such as in the FXHello (code below).

This problem does not occur on MACOS 10.14 Mojave.

Has anyone else experienced this? If so, is there workaround?

Example code taken from the JavaFX samples:

package hellofx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloFX extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
        stage.requestFocus();
    }

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

}
Thomas Andres :

I'm able to reproduce the problem. However, my own real world application doesn't suffer from this problem.

I was able to get rid of it by separating main from application class. And The main class also has to access Desktop.getDesktop. With this separation, also a -Xdock:name="HelloFX" parameter is working, that had no effect previously.

I have no idea why those steps are necessary. The early Desktop calls are also necessary with eralier Mac OS versions to get proper system integration.

package hellofx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Appl extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
        stage.requestFocus();
    }
}
package hellofx;

import java.awt.Desktop;

import javafx.application.Application;

public class HelloFX {

    public static void main(String[] args) {
        registerForMacOSXEvents();
        Application.launch(Appl.class, args);
    }

    protected static void registerForMacOSXEvents() {
        Desktop desktop = Desktop.getDesktop();
        desktop.setAboutHandler(e -> System.out.println("About"));
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=323078&siteId=1