简体   繁体   English

如何在Eclipse Swing项目中使用JavaFX

[英]How to Use JavaFX in Eclipse Swing Project

I'm wanting to use a few JavaFX components in a Swing app (notably JFXPanel for its HTML 5 rendering support). 我想在Swing应用程序中使用一些JavaFX组件(特别是JFXPanel用于HTML 5渲染支持)。 My app is currently set up in Eclipse 4.3 (Kepler) and I have the latest Java 7 JDK installed on my machine. 我的应用程序目前在Eclipse 4.3(Kepler)中设置,我在我的机器上安装了最新的Java 7 JDK。

This tutorial from Oracle suggests that all you have to do is just refer to a JavaFX class and it'll work in a Swing app. Oracle的本教程建议您只需要参考JavaFX类,它就可以在Swing应用程序中运行。 So I type in JFXPanel panel = new JFXPanel() , but Eclipse does not recognize it as a valid Java class. 所以我输入JFXPanel panel = new JFXPanel() ,但Eclipse不认为它是一个有效的Java类。 It does recognize other Java 7 classes, like java.nio . 它确实识别其他Java 7类,如java.nio

I can't figure out how to get Eclipse to recognize JavaFX classes. 我无法弄清楚如何让Eclipse识别JavaFX类。 This question was previously answered about JavaFX in Eclipse. 此问题之前已在Eclipse中回答过有关JavaFX的问题 The first response said that you need to start by creating a new JavaFX project, which I can't do because I already have a fairly developed Swing app. 第一个响应说你需要从创建一个新的JavaFX项目开始,我不能这样做,因为我已经有一个相当开发的Swing应用程序。 The second is to use the e(fx)clipse plugin, but the tutorial also seems to require this. 第二个是使用e(fx)clipse插件,但教程似乎也需要这个。 If there's something special I have to do in order to get a non-JavaFX project in Eclipse to use JavaFX classes, I can't figure out how to do it. 如果为了在Eclipse中使用非JavaFX项目来使用JavaFX类,我必须做些什么特别的事情,我无法弄清楚如何去做。

The problem with JavaFX is that it is not on the default classpath so eclipse won't find it (and your exported swing application won't either unless you use the oracle packaging utility!). JavaFX的问题在于它不在默认的类路径上,所以eclipse不会找到它(除非你使用oracle打包实用程序,否则你导出的swing应用程序也不会!)。

So you have 2 options: 所以你有两个选择:

a) you install e(fx)clipse and modify the projects Buildpath to include the JavaFX-SDK library. a)安装e(fx)clipse并修改项目Buildpath以包含JavaFX-SDK库。

b) you add the jfxrt.jar yourself to the projects Buildpath (you don't need anything else). b)您自己将jfxrt.jar添加到项目Buildpath(您不需要任何其他内容)。

e(fx)clipse would give you extra support for FX development. e(fx)clipse将为您提供FX外汇开发的额外支持。 The version that can be installed into Kepler can be found at http://download.eclipse.org/efxclipse/updates-nightly/site 可以在http://download.eclipse.org/efxclipse/updates-nightly/site找到可以安装到Kepler的版本。

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

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