简体   繁体   English

Java FX代码可在Windows上运行,但不能在Mac OS上运行; 如何在Mac OS上运行JavaFX?

[英]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. 我有一个可以在Windows上运行的JavaFX程序,但是在Mac OS上却无法运行。

I have MacOS Sierra 64bit (latest as of March 11), JDK 8u121, Eclipse IDE - NEON 我有MacOS Sierra 64位(截至3月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 但是,从Windows传输代码似乎存在问题

PS. PS。 I've read about this issue online, but all I have found, are answers for previous operating systems and jdks. 我已经在线阅读了有关此问题的信息,但是我发现的所有内容都是以前的操作系统和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. 我的观察:在Windows上,出现一个对话框,标题为SELECT。

Upon running it on mac, a dialog box appears, but with NO title. 在Mac上运行时,会出现一个对话框,但没有标题。


Now, consider this: 现在,考虑一下:

When I comment out FileDialog, the code works fine, it brings up a 500x500 window. 当我注释掉FileDialog时,代码可以正常工作,它会弹出一个500x500的窗口。 However, when I include the FileDialog part, it gets stuck. 但是,当我包含FileDialog部分时,它会卡住。 (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. 您应该使用JavaFX的FileChooser,而不是AWT FileDialog。 The AWT/Swing components and JavaFX are from different bloodlines and can not readily be intermixed. AWT / Swing组件和JavaFX来自不同血统,不能轻易混合。 The fact that this runs on Windows is more a fluke than anything. 在Windows上运行该事实比任何事情都更为偶然。

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

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