JavaFX WebView Preview

The screenshot below is a preview of a JavaFX WebView. It was created in Processing4 after adding the javafx.webview module to line 1086 of JavaBuild.java and recompiling the editor. The source code and output are shown below :

Source code:

import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;

void setup() {  
  size(1, 1, FX2D);
  Stage stage = new Stage();
  stage.setTitle("JavaFX WebView Example");
  WebView webView = new WebView();
  webView.getEngine().load("http://www.processing.org");
  VBox vBox = new VBox(webView);
  Scene scene = new Scene(vBox, 960, 600);
  stage.setScene(scene);
  stage.show();
}

void draw() {
}

Output:

3 Likes

HI,
amazing, i play with playwright to get webcontent, it works but is heavy and paojects are not easy to move to other computers, i will love to play with javafx
can you give some more intel on how you did that?
do you think, it can be an external library?

—edit—
ok i tried and it’s as easy as you said

still, do you think it can be just having some extra jar in sketch “code” directory or it s something more deeply connected with internal code?

I’m very interested in how you tried this code and your ability to run it. Did you alter line 1086 in “JavaBuild.java” and then recompile the Processing4 editor and run the code in that editor? Or did you run the demo in the distributed Processing4 version?

To answer your inquiry about adding jar files, this is unnecessary. All the jar files for the modules are already in the Documents/Processing/libraries/javafx/library/macos-x86_64/modules folder on my mac. They should be there on your system as well, with the exception you may be using an M1 or M2 chip so you would open the mac-aarch64/modules folder if that is the case. If you look in the modules folder you will see seven jar files which represent the modules for javafx. So it is not a matter of having the correct jar file. Instead it is a matter that the authors of Processing4 only compile three of the seven modules which give the app very limited javafx capability. We are currently working with one of the authors to get all seven included. I have already done this on my revised editor and so far I have not seen any adverse effects.

It’s a piece of cake to revise the editor once you get Homebrew and Apache-Ant installed on your mac. We owe a debt of gratitude to the authors for making their work open source.

Hi,
well…compilation was easy but less afterward
i dont understand what i m doing when playing with javabuild and ant …, so i dont even know what worked of the following steps:
i followed the “how to build the code” on processing github
then edited “JavaBuild.java” as you said, it was not working first run, complaining about some javafx missing,
so i uncommented the 1085 line as i saw was more javafx component was there
"--add-modules", "javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web",

still was not able to find the javafx library, so i copy paste the jars from javafx processing libraries to “code” directory of the sketch and it worked
i guess it mean some other lines edition are needed in javabuild to avoid that last problem but i’m already too far out of my comfort zone

Thank you for the followup. Before I re-compiled the editor I had previously tried putting all the jar files in the Code folder of my button demo and that failed on my system. I’m using the older Intel chip and from your other posts it appears that you are using either the M1 or M2 chip. At any rate, I have another large javafx demo that I will be posting soon and I’ll be anxious to see if you can repeat your success with that code. I appreciate your efforts.

i will be happy to test,
yes i’m on a m1, as i was worry to mess it up, i first did this on a windows machine and it worked the same

thank you for sharing

1 Like

Hi @svan,

Maybe of interest …

Cheers
— mnse