Eclipse Mars won't auto import JavaFX

老子叫甜甜 提交于 2019-12-22 09:23:43

问题


So, for every freaking time I want to use JavaFX 8 component, I have to google the exact name of the package, and manually type

 import packageName;

I'll put in more detail.

Let's say I want to create a StackPane

 StackPane stackPane = new StackPane(new ImageView(this.getClass().getResource("/images/about_icon.png").toString()));
 stackPane.setAlignment(Pos.CENTER);

Several classes there. When I use ctrl + o (cmd + o in Mac), then it should import the required package.

But it doesn't.

In fact, I have to google the exact name of StackPane. So, I googled it, I found it that it's under javafx.scene.layout.StackPane

So, I do import javafx.scene.layout.StackPane;

StackPane is fixed.

Now Eclipse is complaining about ImageView and I'm repeating the above same steps for ImageView.

And so on.

How can this be improved?

I'm using Eclipse Mars. Jdk 8. Mac OS X El-Capitan.


回答1:


You need to install e(fx)clipse in order to have JavaFX development tooling support.

For this

  1. Open Help -> Install New Software
  2. Select the Software Site for Mars http://download.eclipse.org/releases/mars
  3. Disable Group items by category (unfortunately the e(fx)clipse team forgot to add a category)
  4. Filter for e(fx)
  5. Select e(fx)clipse - IDE
  6. Next
  7. Next
  8. Accept the license
  9. Finish

After that you need to restart Eclipse and should have proper JavaFX support.




回答2:


On a clean installation of the latest version of Eclipse for Java Developers (Mars.1 release 4.5.1), I was able to reproduce this (more or less).

I fixed it by setting the access restrictions on the JRE system library.

From your Project properties, choose "Java Build Path", select the "Libraries" tab, and expand the JRE System Library:

The first entry in that list is "Access Rules". Select that and press "Edit", then press "Add":

For "Resolution", choose "Accessible", and for "Rule Pattern", enter "javafx/**".

Hit "OK" until all the dialogs are gone. Your CMD-SHIFT-O options should now be able to find javafx packages.




回答3:


After having learnt my lesson of the day - javafx is not standard java! - I was still curious why I didn't experience any problems with the imports of javafx.*

Actually, I can reproduce the issue in Mars on Win7: all I had to do was to use the public jre as system library of the project. In my environment, I normally use the jdk as system library which doesn't seem to have the problem.

So for Windows, a simple solution (aka: not requiring the installation of additional tooling nor tweaking access permissions on the project level) is to use a java system library backed by a jdk.



来源:https://stackoverflow.com/questions/33383248/eclipse-mars-wont-auto-import-javafx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!