JBCefBrowser, how to properly set HTML string

Answered

In my plugin I have HTML I need to display to my user, which I have as just a String of HTML. I'm trying to use the JBCefBrowser with the following code:

JBCefBrowser myBrowser = new JBCefBrowser();
myBrowser.loadHTML("<html><body>Hello World</body></html>");
myBrowser.openDevtools();

The window will open, but its contents are always blank:

What am I doing wrong?

0
6 comments

Please show more context of your code and specify what IDE version/JBR you're using. Ideally link to your plugin sources to reproduce.

0

Hi Yann! You beat me to it, was about to reply! My problem was just not fully understanding how to use this component. I have it working now with this code:

JBCefBrowser browser = new JBCefBrowser();
browser.loadHTML(html);
browser.getComponent().setPreferredSize(new Dimension(d.width,d.height));
htmlPanel.add(browser.getComponent());

Where "html" is a string of HTML getting passed to my method, and "htmlPanel" is a JPanel.

2

Ran into a similar issue, and found that using BorderLayout made it work for me.

JBCefBrowser browser = new JBCefBrowser();
browser.loadHTML(html);
JPanel htmlPanel = new JPanel(new BorderLayout());
htmlPanel.add(jbCefBrowser.getComponent(), BorderLayout.CENTER);
0

Brandon Atkinson

Sorry to bother you, but I came across the same problem. I tried to new a JPanel like this:

var browser = JBCefBrowser()
browser.loadHTML("<html><body><p>dfasdfas</p></body></html>")
var panel = JPanel()
panel.add(browser.component, BorderLayout.CENTER)

But there was nothing to display. And there was no error created.

 

0

Bing you don't specify BorderLayout in JPanel constructor call

0

Yann Cebron

It still does not work to add BoderLayout

var browser = JBCefBrowser()
browser.loadHTML("<html><body><p>dfasdfas</p></body></html>")
var panel = JPanel(BorderLayout())
panel.add(browser.component, BorderLayout.CENTER)

 

 

0

Please sign in to leave a comment.