简体   繁体   English

不能在intellij idea上使用javafx

[英]can not use javafx on intellij idea

I have problem importing import "javafx.util.Pair" into my program.我在将 import "javafx.util.Pair" 导入我的程序时遇到问题。 after searching the net I've found this answer cannot resolve symbol javafx.application in IntelliJ Idea IDE and I've installed desired jar file but still I've problem to import.在网上搜索后,我发现这个答案无法解析 IntelliJ Idea IDE 中的符号 javafx.application并且我已经安装了所需的 jar 文件,但仍然无法导入。 this is what I face to when open java jdk.这就是我打开 java jdk 时面临的情况。 I don't know the why the "jfxrt.jar" is different.我不知道为什么“jfxrt.jar”是不同的。 note the black arrow on the folder icon注意文件夹图标上的黑色箭头

open the File |打开文件 | Project Structure dialog, there under Platform Settings select SDKs and then your JDK 1.8.项目结构对话框,在平台设置下选择SDK ,然后选择 JDK 1.8。 On the right you then see all the jars that make up the classpath to your SDK.在右侧,您将看到构成 SDK 类路径的所有 jar。 Make sure that your jfxrt.jar is in that list, if not, you can add it by clicking the '+' button at the bottom.确保您的jfxrt.jar在该列表中,如果没有,您可以通过单击底部的“+”按钮添加它。

Update May 2020 2020 年 5 月更新

JavaFX is no longer part of the Oracle or OpenJDK default distributions. JavaFX 不再是 Oracle 或 OpenJDK 默认发行版的一部分。 Instead it is available as a seperate library or module set.相反,它可以作为单独的库或模块集使用。

For instructions on using JavaFX in your application, see the documentation at:有关在应用程序中使用 JavaFX 的说明,请参阅以下文档:

For instructions on working with a modern JavaFX installation and Idea, also see the related question:有关使用现代 JavaFX 安装和 Idea 的说明,另请参阅相关问题:


You don't need to "install the desired jar" (whatever that means).您不需要“安装所需的 jar”(无论这意味着什么)。
You don't need to do that for JavaFX.对于 JavaFX,您不需要这样做。 You should not do anything explicitly with jfxrt.jar either in the filesystem or by adding it to a project classpath.您不应在文件系统中或通过将jfxrt.jar添加到项目类路径中来显式地对jfxrt.jar执行任何操作。 If doing something on the filesystem, that is especially bad as jfxrt.jar is not made to be standalone and requires related native libraries shipped with the JDK in order to work.如果在文件系统上做一些事情,那尤其糟糕,因为 jfxrt.jar 不是独立的,并且需要与 JDK 一起提供的相关本地库才能工作。

The JavaFX code should be part of the JDK installation you are using. JavaFX 代码应该是您正在使用的 JDK 安装的一部分。 Perhaps you are using a Java version below 8 or an OpenJDK implementation that does not include JavaFX.也许您使用的是低于 8 的 Java 版本或不包含 JavaFX 的 OpenJDK 实现。 If so, then install the Oracle JDK 8+ and set idea to use it .如果是这样,请安装Oracle JDK 8+设置idea 以使用它 Everything should just work then and all of related JavaFX imports will resolve.一切都应该正常工作,所有相关的 JavaFX 导入都会解决。

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

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