如何在Eclipse Swing项目中使用JavaFX [英] How to Use JavaFX in Eclipse Swing Project

查看:114
本文介绍了如何在Eclipse Swing项目中使用JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Swing应用程序中使用一些JavaFX组件(特别是JFXPanel的HTML 5渲染支持).我的应用程序当前在Eclipse 4.3(Kepler)中设置,并且我的计算机上安装了最新的Java 7 JDK.

I'm wanting to use a few JavaFX components in a Swing app (notably JFXPanel for its HTML 5 rendering support). My app is currently set up in Eclipse 4.3 (Kepler) and I have the latest Java 7 JDK installed on my machine.

本教程建议您所要做的只是引用JavaFX类,它将在Swing应用程序中工作.因此,我键入JFXPanel panel = new JFXPanel(),但是Eclipse无法将其识别为有效的Java类.它可以识别其他Java 7类,例如java.nio.

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. So I type in JFXPanel panel = new JFXPanel(), but Eclipse does not recognize it as a valid Java class. It does recognize other Java 7 classes, like java.nio.

我不知道如何让Eclipse识别JavaFX类. 此问题以前是关于Eclipse中JavaFX的回答.第一个答复说,您需要先创建一个新的JavaFX项目,但由于我已经有一个相当发达的Swing应用程序,所以我不能这样做.第二种是使用e(fx)clipse插件,但是教程似乎也要求这个.如果为了使Eclipse中的非JavaFX项目使用JavaFX类而必须做些特殊的事情,我将不知道该怎么做.

I can't figure out how to get Eclipse to recognize JavaFX classes. This question was previously answered about JavaFX in Eclipse. 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. The second is to use the e(fx)clipse plugin, but the tutorial also seems to require this. 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.

推荐答案

JavaFX的问题在于它不在默认的类路径上,因此eclipse找不到它(除非使用oracle打包实用程序!).

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!).

因此,您有2个选择:

a)您安装 e(fx)clipse 并修改项目Buildpath以包括JavaFX-SDK库.

a) you install e(fx)clipse and modify the projects Buildpath to include the JavaFX-SDK library.

b)您将jfxrt.jar自己添加到项目Buildpath中(您不需要其他任何东西).

b) you add the jfxrt.jar yourself to the projects Buildpath (you don't need anything else).

e(fx)clipse将为您提供对FX开发的额外支持.可以在 http://download.eclipse.org中找到可以安装到开普勒的版本. /efxclipse/updates-nightly/site

e(fx)clipse would give you extra support for FX development. The version that can be installed into Kepler can be found at http://download.eclipse.org/efxclipse/updates-nightly/site

这篇关于如何在Eclipse Swing项目中使用JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆