Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)
To load a web page by its URL use the Browser.loadURL() method. The following code demonstrates how to load http://www.google.com web page: (要通过URL加载网页,请使用Browser.loadURL()方法。以下代码演示了如何加载http://www.google.com网页:)
browser.loadURL("http://www.google.com");
Same method can be used for loading a HTML file from a local file system. Instead of URL you just need to provide absolute path to HTML file. For example:(可以使用相同的方法从本地文件系统加载HTML文件。除了URL,您只需要提供HTML文件的绝对路径即可。例如:)
browser.loadURL("C:\\path\\index.html");
The web page will be loaded asynchronously, so there's no guarantee that Google web page will be loaded completely when the method returns.(该网页将异步加载,因此无法保证方法返回时将完全加载Google网页。)
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 browserView = new BrowserView(browser); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(browserView, BorderLayout.CENTER); frame.setSize(700, 500); frame.setLocationRelativeTo(null); frame.setVisible(true); browser.loadURL("http://www.google.com"); } }