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