————————————————————————————————————————————————
Operating system: Ubuntu18.04
EclipseVersion: Oxygen.3a Release (4.7.3a)Build id: 20180405-1200
————————————————————————————————————————————————
Eclipse cannot support javafx by default. Perform the following operations 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, the Edit Access Rule form pops up, select Accessible for Resolution option, and fill in "javafx/**" for Rule Pattern option
This will allow you to use javafx directly in Eclipse.
Try writing a helloworld:
package start; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class start extends Application{ public static void main( String[] args) { System.out.println("hello,world"); launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Hello World!"); Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("HelloWorld!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show(); } }
Note that there is a Gtk-Message on it that says "canberra-gtk-module" could not be loaded
The solution is as follows:
Open the terminal and execute the following command to install the module
sudo apt-get install libcanberra-gtk-module
Run it again, live it up.