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?

2 comments
Comment actions Permalink

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
Comment actions Permalink

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.

1

Please sign in to leave a comment.