如何在Eclipse中为JavaFX类启用自动导入? [英] How to enable auto import in Eclipse for JavaFX classes?

查看:142
本文介绍了如何在Eclipse中为JavaFX类启用自动导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的Eclipse是Oxygen.2版本(4.7.2),其中有Java 9.0.1.从本质上讲,Java 9可以工作,尤其是自动导入(适用于普通"类和程序包)有效,但是自动导入(和自动完成)不适用于javafx.*.如果我手动键入import java并按 Ctrl + Space ,则会弹出匹配包列表,在其中可以看到javafx.*层次结构.但是当我输入import javafx.stage并按 Ctrl + Space ,它将自动添加.*;,并且在程序包中不显示任何类.当我在方法正文中的某处键入Stage并按 Ctrl + Space 时,没有任何建议.但是,当我键入一个导入(例如import javafx.stage.Stage)时,代码便会编译并运行.

My current Eclipse is Oxygen.2 Release (4.7.2) and there's Java 9.0.1. Essentially Java 9 works and particularly auto import works (for "ordinary" classes and packages), but auto import (and autocompletion) does not work for javafx.*. If I manually type import java and press Ctrl+Space, then list of matching packages pops up where I can see javafx.* hierarchy. But when I type e.g. import javafx.stage and press Ctrl+Space it automatically adds .*; and does not display any classes in the package. When I type Stage somewhere in the method body and press Ctrl+Space, there are no suggestions for it. However when I type add an import (like import javafx.stage.Stage) then code compiles and runs.

任何线索都说明了如何解决自动完成和自动导入功能(正如我所说的那样,该功能适用​​于其他类,例如java.time.LocalDateTime或其他).

Any clues how to fix auto completion and auto import feature (which, as I said, works for other classes, like for instance java.time.LocalDateTime or many othres).

推荐答案

javafx*类由于受访问规则控制对系统程序包的访问而在代码完成期间被阻止.例如,查看 Eclipse错误527353 动态计算Eclipse Oxygen中尚未完成可访问软件包的列表.结果,只有

javafx* classes are blocked during code completion due to access rules governing the access to system packages. Looking at, e.g., Eclipse bug 527353 the mechanism for dynamically computing the list of accessible packages had not been finalized in Eclipse Oxygen. As a result, only a static profile can be used. That file currently mentions:

注意: JavaSE-9 配置文件尚未完成.

NOTE: The JavaSE-9 profile is not yet finalized.

由于根据 JEP 261 进行的动态计算包括javafx软件包-如果有的话- ,我认为静态配置文件也应列出这些配置文件,或者仅出于完全依赖 JPMS 规则而被放弃.

Since dynamic computation according to JEP 261 includes the javafx packages - if available -, I think the static profile should list those as well, or be abandoned in favor of fully relying on JPMS rules, only.

但是,可以通过在

Java Build Path > Libraries > JRE System Library > Access rules.

这篇关于如何在Eclipse中为JavaFX类启用自动导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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