————————————————————————————————————————————————
Operating system: Ubuntu18.04
eclipseversion:oxygen.3a Release (4.7.3a) Build id:20180405-1200
————————————————————————————————————————————————
Eclipse does not support JavaFX by default and does the following to enable access to JavaFX
1. Right-click the project->bildpath->configure Bild Path, select the Library tab, select Access rules, and click Edit on the right.
Click Add on the pop-up typeaccessrules form, pop-up the edit Access Rule form, resolution option select the Accessible,rule pattern option to fill in "javafx/**"
In this way, you can use JavaFX directly in Eclipse.
Write a HelloWorld try:
Packagestart;Importjavafx.application.Application;Importjavafx.event.ActionEvent;ImportJavafx.event.EventHandler;ImportJavafx.scene.Scene;ImportJavafx.scene.control.Button;ImportJavafx.scene.control.Label;ImportJavafx.scene.image.Image;ImportJavafx.scene.layout.StackPane;ImportJavafx.stage.Stage; Public classStartextendsapplication{ Public Static voidMain (string[] args) {System.out.println ("Hello,world"); Launch (args); } @Override Public voidStart (Stage primarystage) {primarystage.settitle ("Hello world!"); Button btn=NewButton (); Btn.settext ("Say ' Hello World '"); Btn.setonaction (NewEventhandler<actionevent>() {@Override Public voidhandle (ActionEvent event) {System.out.println ("Helloworld!"); } }); Stackpane Root=NewStackpane (); Root.getchildren (). Add (BTN); Primarystage.setscene (NewScene (Root, 300, 250)); Primarystage.show (); } }
Note that there is a gtk-message that says "Canberra-gtk-module" cannot be loaded
The solution is as follows:
Open Terminal execute the following command to install the module can be
sudo apt-get install Libcanberra-gtk-module
Run again, snap alive.
Eclipse uses JavaFX to write a helloworkld