java-cef icon indicating copy to clipboard operation
java-cef copied to clipboard

Provide JavaFX node for JCEF

Open magreenblatt opened this issue 10 years ago • 68 comments

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...

magreenblatt avatar Mar 20 '15 08:03 magreenblatt

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.

magreenblatt avatar Apr 07 '15 20:04 magreenblatt

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);

magreenblatt avatar Jul 29 '15 15:07 magreenblatt

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.

magreenblatt avatar Oct 27 '15 23:10 magreenblatt

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.

magreenblatt avatar Oct 28 '15 21:10 magreenblatt

Original comment by Roberto Neto (Bitbucket: BetoN, GitHub: BetoN).


Any news for this issue?

magreenblatt avatar Mar 07 '17 13:03 magreenblatt

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.

magreenblatt avatar Mar 10 '17 08:03 magreenblatt

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.

magreenblatt avatar Mar 10 '17 14:03 magreenblatt

Original comment by Roberto Neto (Bitbucket: BetoN, GitHub: BetoN).


@aaon, can you provide a simple example ?

magreenblatt avatar Apr 19 '17 12:04 magreenblatt

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 );
}

}

magreenblatt avatar Apr 19 '17 13:04 magreenblatt

Original comment by DragonWarri0r (Bitbucket: DragonWarri0r, GitHub: DragonWarri0r).


@aaon, it`s works, but very-very slow

magreenblatt avatar Apr 21 '17 16:04 magreenblatt

Original comment by Aaron Ong (Bitbucket: Aaron Ong).


You'll have to go native if you want a proper JavaFX implementation of JCEF btw

magreenblatt avatar Apr 26 '17 10:04 magreenblatt

Original comment by kalemsj (Bitbucket: kalemsj, GitHub: kalemsj).


Any news for this issue?

magreenblatt avatar Apr 16 '18 02:04 magreenblatt

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.

magreenblatt avatar Jun 28 '18 10:06 magreenblatt

A PR to add this functionality could be accepted if the changes are reasonable in scope.

magreenblatt avatar Jun 28 '18 20:06 magreenblatt

Original comment by truejasonxiefans (Bitbucket: truejasonxiefans).


Any further news or plan for this feature?. We are suffering from intergrating the JCEF into JavaFX.

magreenblatt avatar Aug 03 '18 03:08 magreenblatt

Original comment by Marcus Ataide (Bitbucket: Marcus Ataide).


Any news?

magreenblatt avatar Sep 19 '18 22:09 magreenblatt

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?

magreenblatt avatar Nov 15 '18 15:11 magreenblatt

Original comment by Jakub Šmíd (Bitbucket: xjakubs, GitHub: xjakubs).


any news? I tried JxBrowser, but it is licensed :-(

magreenblatt avatar Jan 07 '19 23:01 magreenblatt

Original comment by Vinicius Lemes Da Silva (Bitbucket: Vinicius Lemes).


Any news on this?

magreenblatt avatar Apr 10 '19 12:04 magreenblatt

Original comment by uptonking (Bitbucket: uptonking, GitHub: uptonking).


any news?

magreenblatt avatar Jun 09 '19 12:06 magreenblatt

Original comment by doni mbeng (Bitbucket: jeffartdo).


Hello did some have solution about JCEF into JavaFX

magreenblatt avatar Jun 12 '19 19:06 magreenblatt

Original comment by ZUchiha Shishui (Bitbucket: zuchiha shishui).


Hi Dev. Please add JCEF to JavaFX. Pleaseeeeeeeeeeeeee

magreenblatt avatar Jul 02 '19 13:07 magreenblatt

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.

magreenblatt avatar Jul 15 '19 21:07 magreenblatt

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?

magreenblatt avatar Aug 09 '19 04:08 magreenblatt

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.

magreenblatt avatar Aug 09 '19 11:08 magreenblatt

Original comment by Omar Mainegra (Bitbucket: Omar Mainegra).


News about this?

magreenblatt avatar Feb 09 '20 19:02 magreenblatt

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.

magreenblatt avatar Feb 20 '20 13:02 magreenblatt

Original comment by laram (Bitbucket: laram, GitHub: laram).


News about this?

magreenblatt avatar Feb 23 '20 17:02 magreenblatt

Original comment by Lucas Owen (Bitbucket: Lucas Owen).


this needs to be top priority IMO

magreenblatt avatar Mar 24 '20 19:03 magreenblatt

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:

  1. Is backward compatibility with Swing required? I noticed that CefBrowserWr and CefBrowerOsr are pretty strongly coupled to Swing.
  2. 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:

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.

magreenblatt avatar Jun 01 '20 22:06 magreenblatt