java-cef
java-cef copied to clipboard
Provide JavaFX node for JCEF
Original report by sebastian klaar (Bitbucket: sebastian klaar).
I'd like to use JCEF with JavaFX. It seems not possible to do this via a SwingNode. The only option I see is to provide a JavaFX node instead of AWT.
JavaFX-WebView is not an option, since there is no WebGL support...
Original comment by Patrick Sweeney (Bitbucket: Klobersaurus).
I have been wanting this for months. The JavaFX WebView is not cutting it from a Javascript performance standpoint. I also tried with the SwingNode but JCEF would not render, at all. SwingNode has a disclaimer saying that it cannot render anything too complicated.
Original comment by Anand Tiwari (Bitbucket: anandktiwari26, GitHub: anandktiwari26).
Hello Sebastian Klaar, Try it.
CefApp cefApp_ = CefApp.getInstance(); CefClient client_ = cefApp_.createClient(); CefBrowser browser_ = client_.createBrowser("https://www.google.com", OS.isLinux(), false); Component browerUI_ = browser_.getUIComponent(); JPanel panel = new JPanel(); panel.add(browerUI_); SwingNode swingNode = new SwingNode(); swingNode.setContent(panel);
Original comment by Patrick Sweeney (Bitbucket: Klobersaurus).
Anand Tiwari, I just tried this and had no luck. Did you actually manage to get this to work? I'm developing against JDK8u40 64-bit on Windows 7.
Here's some information on JOGL's attempts to integrate with JavaFX: https://jogamp.org/bugzilla/show_bug.cgi?id=607. Sounds like using JOGL + JavaFX on Windows at least is not currently possible, so we would be looking at developing an alternative JavaFX-based off-screen rendering implementation to completely replace the JOGL usage. I'm not sure what would be required to support windowed JCEF with JavaFX or if that even makes sense given JavaFX's intended usage.
Original comment by Aaron Ong (Bitbucket: Aaron Ong).
Hi. I needed to embed CEF into our pre-existing JavaFX UI as well, so I did a little experimenting. What worked for me was going into the CefBrowserOsr.java file, and changing the type of canvas_ from GLCanvas to GLJPanel, which is a lightweight component that's compatible with JavaFX's SwingNode. The two classes seem to be mostly equivalent, so you don't have to change any method calls to canvas_.
The only caveat with this approach is that you must use OSR mode for this to work, but I'll take anything I can get at this point. I also haven't checked if there are any side effects, but I've tested it a bit so far and it seems to be enough for our use case.
Edit: The only issue I've seen so far is that backspace, tab, and certain other keys don't work when embedded in a SwingNode, but they do when using Swing.
Original comment by Aaron Ong (Bitbucket: Aaron Ong).
I did a little more digging, and it turns out that the problem with the backspace key was due to JavaFX's different way of handling key events. It took a bit of hackery, but I created a new SwingNode class that overrides the default key handling behavior of the original JavaFX version: http://pastebin.com/EA26Mz6m
The main difference here starts at line 45, where it just copies the key code value (cast into a char) to the key char value if key char's integer value is 0. I'm not sure if this is entirely correct, but I was able to get backspace to work, at least.
Original comment by Roberto Neto (Bitbucket: BetoN, GitHub: BetoN).
@aaon, can you provide a simple example ?
Original comment by Aaron Ong (Bitbucket: Aaron Ong).
I can't test this right now because I don't have the right environment. This one uses the modified SwingNode I provided to make the backspace key work. Some other keys still don't work correctly though, so I guess it still needs some more remapping.
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; import org.cef.CefApp; import org.cef.CefClient; import org.cef.browser.CefBrowser;
import javax.media.opengl.awt.GLJPanel;
public class CefBrowserSample extends Application {
@Override
public void start( Stage primaryStage ) {
Pane root = new Pane();
SwingNode swingNode = new SwingNode();
root.getChildren().add( swingNode );
Scene scene = new Scene( root, 500, 500 );
primaryStage.setTitle( "JCEF Example" );
primaryStage.setScene( scene );
CefApp app = CefApp.getInstance();
CefClient client = app.createClient();
CefBrowser browser = client.createBrowser( "www.google.com", true, false );
swingNode.setContent( ( GLJPanel) browser.getUIComponent() );
primaryStage.show();
}
public static void main( String[] args ) {
launch( args );
}
}
Original comment by DragonWarri0r (Bitbucket: DragonWarri0r, GitHub: DragonWarri0r).
@aaon, it`s works, but very-very slow
Original comment by Aaron Ong (Bitbucket: Aaron Ong).
You'll have to go native if you want a proper JavaFX implementation of JCEF btw
Original comment by iltaf khalid (Bitbucket: iltaf, GitHub: iltaf).
I am also stuck at this point on integrating JavaFX with JCEF. I wish JCEF guys natively support JavaFX so that we avoid all the hacks while compromising on performance etc.
A PR to add this functionality could be accepted if the changes are reasonable in scope.
Original comment by truejasonxiefans (Bitbucket: truejasonxiefans).
Any further news or plan for this feature?. We are suffering from intergrating the JCEF into JavaFX.
Original comment by Marcus Ataide (Bitbucket: Marcus Ataide).
Any news?
Original comment by Former user (Bitbucket: Former user).
Is there any news about this issue?
Also, I see from earlier comments that many people wanted this feature long time ago. Is there anyone who can share if they found a hack/temporary solution? Is it possible to get a ~not perfect~ but decent performance in JavaFX?
Original comment by Jakub Šmíd (Bitbucket: xjakubs, GitHub: xjakubs).
any news? I tried JxBrowser, but it is licensed :-(
Original comment by Vinicius Lemes Da Silva (Bitbucket: Vinicius Lemes).
Any news on this?
Original comment by doni mbeng (Bitbucket: jeffartdo).
Hello did some have solution about JCEF into JavaFX
Original comment by ZUchiha Shishui (Bitbucket: zuchiha shishui).
Hi Dev. Please add JCEF to JavaFX. Pleaseeeeeeeeeeeeee
Original comment by Chigozirim Chukwu (Bitbucket: smac89, GitHub: smac89).
There is a promising project which could potentially allow one to embed a GLCanvas in a javafx node (not SwingNode).
https://github.com/eclipse-efx/efxclipse-drift
I have a ready-to-go fork which uses gradle to run the application so you can see it in action:
https://github.com/smac89/efxclipse-drift
If anyone has the know-how, they can contribute to this project so that we can see this happen sooner than later.
Original comment by ZUchiha Shishui (Bitbucket: zuchiha shishui).
This issue have existed since 2015, now In 2019, They couldn’t fixed it. What are they doing?
Original comment by Dominik (Bitbucket: domino2, GitHub: domino2).
From my view of perspective, this should be highly prioritize as web technologies are taking over the desktop for long time already and I suppose that we want to keep Java as good desktop gui as it was. Out there are not so good GUI frameworks and result of this issue can boost right direction and potentially offer nice transferability to different CEF implementation.
Original comment by Omar Mainegra (Bitbucket: Omar Mainegra).
News about this?
Original comment by Bohdan Shkliarenko (Bitbucket: Bohdan Shkliarenko).
What about new PixelBuffer in OpenJFX 13? Or NativeFX project?
I saw some experiments with new PixelBuffer and vlcj (https://twitter.com/hashtag/vlcj)
I think we all are getting closer to use cef project inside JavaFX without swing.
Original comment by Lucas Owen (Bitbucket: Lucas Owen).
this needs to be top priority IMO
Original comment by Mitch Francis (Bitbucket: Mitch Francis).
There seems to be a few questions that need to be answered before this can be resolved:
- Is backward compatibility with Swing required? I noticed that CefBrowserWr and CefBrowerOsr are pretty strongly coupled to Swing.
- Is JOGL (JAMP) the preferred API for working in JavaFX? JAMP 2.40 includes NewtCanvasFX that may be suitable, but this differs from the Prism API used at the base of JavaFX Nodes. Would there be any benefit in adapting to Prism?
My thoughts on a solution are the following
Create a CefView class that derives from Parent and either:
- Code the class to leverage the JOGL NewtCanvasFX (2.40). The CefBrowserWr and CefBrowserOsr classes would would need some glue code to bind the jogl logic to the Node API. I’m still getting up to speed on this, but I know it means the Java.awt event code might need addressing. Update: A few native calls passing component would need updating as well. I am reviewing this NewtCanvasFX example: https://gouessej.wordpress.com/2020/04/05/javafx-et-jogl-fonctionnent-ensemble-javafx-and-jogl-work-together/
OR
- Create a Prism based adaptation of CefBrowserWr and CefBrowserOsr. Not sure if this is the easier path (It looked like a bit of work) but might make it easier to use JFX GraphicsContext. I can’t speak to the performance of Prism. Don’t know enough about it. Maybe someone can provide more detail.
I’m still digging to understand the complexities, but have a vested interest in solving this issue. Feel free to provide an details or insights if I have overlooked something critical.