jcef in javafx get blank page

Having problems with building or using the JCEF Java binding? Ask your questions here.

jcef in javafx get blank page

Postby stoneMulti3 » Tue Aug 01, 2023 4:37 am

jcefmaven version:110.0.25
javafx version:20.0.1
java version:17.0.7
only display a small black square at the top-left corner. Nothing printed after
initialize on Thread[AWT-EventQueue-0,6,main] with library path xxx

Code: Select all
public class JavaFXApp extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        SwingNode swingNode = new SwingNode();
        SwingUtilities.invokeAndWait(() -> {
            String startURL = "http://localhost:28849/#/";
            boolean useOSR = OS.isLinux();
            boolean isTransparent = false;
            //Create a new CefAppBuilder instance
            CefAppBuilder builder = new CefAppBuilder();
            // windowless_rendering_enabled must be set to false if not wanted.
            builder.getCefSettings().windowless_rendering_enabled = useOSR;
            try {
                builder.setInstallDir(ResourceUtils.getFile("classpath:jcef-bundle"));
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
            //Configure the builder instance
            // builder.setInstallDir(new File("jcef-bundle")); //Default
            // builder.setProgressHandler(new ConsoleProgressHandler()); //Default
            // builder.addJcefArgs("--disable-gpu"); //Just an example
            builder.getCefSettings().windowless_rendering_enabled = useOSR; //Default - select OSR mode

            //Set an app handler. Do not use CefApp.addAppHandler(...), it will break your code on MacOSX!
            builder.setAppHandler(new MavenCefAppHandlerAdapter() { });

            //Build a CefApp instance using the configuration above
            CefApp app = null;
            try {
                app = builder.build();
            } catch (Exception e) {
                log.error(e);
                throw new RuntimeException(e);
            }
            CefClient client = app.createClient();
            CefBrowser browser = client.createBrowser(startURL, useOSR, isTransparent);
            Component browserUI = browser.getUIComponent();
            JPanel panel = new JPanel();
            panel.setSize(800, 600);
            panel.add(browserUI, BorderLayout.CENTER);
            swingNode.setContent(panel);
        });
        primaryStage.setScene(new Scene(new javafx.scene.Group(swingNode)));
        primaryStage.show();
    }
}
stoneMulti3
Newbie
 
Posts: 3
Joined: Tue Aug 01, 2023 4:28 am

Re: jcef in javafx get blank page

Postby KatrinaS » Wed Aug 02, 2023 11:12 pm

Maybe :

Code: Select all
Component browserUI = browser.getUIComponent();
browserUI.setPreferredSize(new Dimension(800, 600));
...
primaryStage.pack();
primaryStage.show();
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm

Re: jcef in javafx get blank page

Postby stoneMulti3 » Thu Aug 03, 2023 10:00 pm

KatrinaS wrote:Maybe :

Code: Select all
Component browserUI = browser.getUIComponent();
browserUI.setPreferredSize(new Dimension(800, 600));
...
primaryStage.pack();
primaryStage.show();

1.primaryStage dosen't have method pack
2.after add
Code: Select all
browserUI.setPreferredSize(new Dimension(800, 600));
,it succesed to trigger loading web (cause it printed the fault of web),but still can't rander the web ,only shows a big black square
stoneMulti3
Newbie
 
Posts: 3
Joined: Tue Aug 01, 2023 4:28 am

Re: jcef in javafx get blank page

Postby stoneMulti3 » Thu Aug 03, 2023 10:08 pm

i'v tried the same code with swing.It works well.I'll mix swing with javafx untill it works on javafx
stoneMulti3
Newbie
 
Posts: 3
Joined: Tue Aug 01, 2023 4:28 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 122 guests