0

I am new to IDEA. I run version Community 2020.1 and Gluon SceneBuilder 11.0.1 with JDK 11.0.2 and javafx-sdk 11.0.2 under Windows 10. I wrote a small test program, required adding a lot to run configurations, thanks to Egor Klepikov (IntelliJ). Here is the code of the controller:

public class Controller {
    public Button btn1;
    public WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    public Button showBtn;
    String fpath;

    @FXML
    public void initialize() {
//        System.out.println("in controller initialize");
        File file = new File(String.valueOf(getClass().getResource("RateCalculatorHelp.html")));
        fpath = file.getPath();
//        System.out.println("Path: " + fpath);
        webEngine.load(fpath);
   }

    public void showHtml(ActionEvent actionEvent) {
        webView.setVisible(true);
     }
}

When I run the application, there is no error message but my html file does not show up. I could not find out why !!! Help most welcome.

PS Is there a way to attach a file with the project to my message ?

1 Answers1

0

I got my answer from Egor Klepikov (IntelliJ). The webEngine variable initialization as to be moved to the controller initialize() method, and ta application will work ! Here is the revised code:

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

import java.io.File;

public class Controller {
    public Button btn1;
    public WebView webView; // = new WebView();
    WebEngine webEngine; // = webView.getEngine();
    public Button showBtn;
    String fpath;

    @FXML
    public void initialize() {
//        System.out.println("in controller initialize");
        webEngine = webView.getEngine();
        File file = new File(String.valueOf(getClass().getResource("RateCalculatorHelp.html")));
        fpath = file.getPath();
//        System.out.println("Path: " + fpath);
        webEngine.load(fpath);
   }

    public void showHtml(ActionEvent actionEvent) {
        webView.setVisible(true);
     }
}

As I mentioned in the initial message, I had to add a lot to the VM options of the IDEA run configuration. Here is the list:

--module-path
D:\JavaFX\javafx-sdk-11.0.2\lib
--add-modules
javafx.controls,javafx.fxml
--add-exports
javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.util=ALL-UNNAMED
--add-exports
javafx.base/com.sun.javafx.logging=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.prism=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.geom.transform=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.glass.utils=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.font=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
--add-exports
javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.scene.input=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.prism.paint=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.scenario.effect=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.text=ALL-UNNAMED
--add-exports
javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED

I realize this happens because JavaFX is no longer a part of the JDK since version 11. I hope someone will make it more practical to use javaFX in the future!