JCEF BrowserUI not displaying in JFrame or Ja
Posted: Fri Apr 19, 2019 5:31 am
I've been trying to add the JCEF browser to a JFrame created with the Swing UI Builder in NetBeans. Unfortunately, if I try to add it to a JFrame or JPanel I create using this tool, it does not work. The Swing window appears, but it is simply empty.
The same happens with a JPanel.
However, when I programatically initiate a new, separate JFrame window, it works perfectly.
Why is this happening? How can I get it to work in any other JFrame or JPanel?
- Code: Select all
final CefApp cefApp = CefApp.getInstance();
final CefClient client = cefApp.createClient();
final CefBrowser browser = client.createBrowser("http://www.google.com", OS.isWindows(), false);
final Component browserUI = browser.getUIComponent();
getContentPane().add(browserUI, BorderLayout.CENTER);
The same happens with a JPanel.
- Code: Select all
jPanel1.add(browserUI, BorderLayout.CENTER);
However, when I programatically initiate a new, separate JFrame window, it works perfectly.
- Code: Select all
final JFrame mainFrame = new JFrame();
getContentPane().add(browserUI, BorderLayout.CENTER);
mainFrame.setSize(800, 600);
mainFrame.setVisible(true);
Why is this happening? How can I get it to work in any other JFrame or JPanel?