将JxBrowser内容添加到JPanel

时间:2014-07-20 12:03:56

标签: java html jframe jpanel jxbrowser

是否无法将jxbrowser内容添加到jpanel。当我将jxBrowser内容添加到JFrame时,很容易看到它。但是我无法将jxBrowser内容添加到jpanel。我不知道是不可能还是我无法将jxBrowser内容添加到jpanel。

2 个答案:

答案 0 :(得分:2)

以下是演示如何将JxBrowser Browser组件嵌入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");
    }
}

您可以在https://jxbrowser.support.teamdev.com/support/solutions/9000049010

找到更多样本

答案 1 :(得分:0)

实际上jxbrowser能够添加到Jpanel中。 我遇到了同样的问题。这只是因为我在initilize BorderLayout时没有指定JPanel。代码打击没问题。

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