https://github.com/jgcodes2020/JChrome
When I run the program, JCEF loads the page I coded it to. However, the program seems to not respond to input. I can't interact with JCEF or the Swing controls. What causes this and how can I fix it?
public class JCLauncher {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JCFrame jcFrame = new JCFrame("www.google.ca");
});
}
}
public class JCFrame extends JFrame {
CefClient client; CefBrowser browser;
public JCFrame(String url) {
CefApp cef = CefApp.getInstance();
client = cef.createClient();
browser = client.createBrowser(url, false, false);
this.add(browser.getUIComponent(), BorderLayout.CENTER);
this.setSize(800, 600);
this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
JCFrame.this.dispose();
CefApp.getInstance().dispose();
}
});
}
}
public class JCFrame extends JFrame {
private final CefApp cefInstance;
CefClient client; CefBrowser browser;
public JCFrame(String... cefArgs) {
CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
@Override
public void stateHasChanged(CefApp.CefAppState state) {
if (state == CefApp.CefAppState.TERMINATED) System.exit(0);
}
});
CefSettings settings = new CefSettings();
boolean useOSR = (Arrays.binarySearch(cefArgs, "-osr") >= 0);
settings.windowless_rendering_enabled = useOSR;
cefInstance = CefApp.getInstance(settings);
client = cefInstance.createClient();
browser = client.createBrowser("www.google.ca", useOSR, false);
this.add(browser.getUIComponent());
this.setVisible(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
cefInstance.dispose();
dispose();
}
});
}
}
Users browsing this forum: No registered users and 11 guests