简体   繁体   中英

Java FX code works on Windows, but not on Mac OS; How Do I Run JavaFX on Mac OS?

I have a JavaFX program that works on Windows, but fails to work on Mac OS.

I have MacOS Sierra 64bit (latest as of March 11), JDK 8u121, Eclipse IDE - NEON

Here is the behavior: On pressing "RUN", the coffee cup shows up in the dock, but everything freezes. I then have to force quit it.

Something important that I noticed: When I write a test app ( eg a borderpane with a button) it works perfectly fine. However, there seems to been an issue in transferring code from windows

PS. I've read about this issue online, but all I have found, are answers for previous operating systems and jdks.

UPDATE:

Consider this:

import java.awt.FileDialog;
import java.awt.Frame;
public class testClass{
    public static void main(String[] args){
        FileDialog fd = new FileDialog(new Frame(), "SELECT", FileDialog.LOAD);
        fd.setVisible(true);
    }
}

My Observation: On Windows, A Dialog Box appears with SELECT as the title.

Upon running it on mac, a dialog box appears, but with NO title.


Now, consider this:

When I comment out FileDialog, the code works fine, it brings up a 500x500 window. However, when I include the FileDialog part, it gets stuck. (Not Responding)

import java.awt.FileDialog;
import java.awt.Frame;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class testClass extends Application{
    public static void main(String[] args){
        launch(args);

    }

    @Override
    public void start(Stage stage) throws Exception {
        FileDialog fd = new FileDialog(new Frame(), "LOAD", FileDialog.LOAD);
        fd.setVisible(true);

        Group g = new Group();
        Scene scene = new Scene(g, 500, 500);
        stage.setScene(scene);
        stage.show();
    }

}

Does anyone have any thoughts on how to resolve this issue?

You should be using JavaFX's FileChooser, not an AWT FileDialog. The AWT/Swing components and JavaFX are from different bloodlines and can not readily be intermixed. The fact that this runs on Windows is more a fluke than anything.

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