3

Is it not possible to add jxbrowser contents to jpanel. When I add jxBrowser content to JFrame, it is seen very easily. But I am not able to add jxBrowser content to jpanel. I don't know if it is not possible or I am not able to add jxBrowser contents to jpanel.

user3857792
  • 43
  • 1
  • 3

2 Answers2

2

Here's sample code that demonstrates how to embed JxBrowser Browser component into JPanel:

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;

/**
 * This sample demonstrates how to create Browser instance,
 * embed it into Swing BrowserView container, display it in JFrame and
 * navigate to the "www.google.com" web site.
 */
public class BrowserSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);

        JPanel panel = new JPanel(new BorderLayout());
        panel.add(view, BorderLayout.CENTER);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(panel, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        browser.loadURL("https://google.com");
    }
}

More samples you can find at https://jxbrowser.support.teamdev.com/support/solutions/9000049010

Vladimir
  • 1
  • 1
  • 23
  • 30
0

Actually jxbrowser is able to added into Jpanel. I have met the same problem. It is just because I did not specify BorderLayout when initilize JPanel. The code blow is alright.

JPanel panel = new JPanel(new BorderLayout());