在基于 Java 的桌面应用程序中嵌入浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1454652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embed browser in Java based desktop application
提问by jrhicks
Possible Duplicate:
Is there a way to embed a browser in Java?
可能的重复:
有没有办法在 Java 中嵌入浏览器?
How can I embed a browser in a Java based desktop application? Can I communicate with the embedded browser directly (not via localhost)... such as loading html text, capturing onclick events, getting form values?
如何在基于 Java 的桌面应用程序中嵌入浏览器?我可以直接与嵌入式浏览器通信(而不是通过 localhost)...例如加载 html 文本、捕获 onclick 事件、获取表单值?
Thanks
谢谢
采纳答案by Omry Yadan
check out Eclipse, it has an embedded browser which is configurable by the user (they support multiple browsers).
查看 Eclipse,它有一个嵌入式浏览器,可由用户配置(它们支持多个浏览器)。
you can probably embed their browser even if you use an AWT based application using the AWT_SWT bridge.
即使您使用 AWT_SWT 桥接器使用基于 AWT 的应用程序,您也可以嵌入他们的浏览器。
this articlemay help you get started.
这篇文章可能会帮助您入门。
回答by kgiannakakis
You can build a very primitive browser using JEditorPane. You can listen to Hyperlinkevents, but javascript or getting form values isn't possible.
您可以使用JEditorPane构建一个非常原始的浏览器。您可以收听Hyperlink事件,但无法使用 javascript 或获取表单值。
回答by JuanZe
Swing JEditor pane is able to display HTML.
Swing JEditor 窗格能够显示 HTML。
Check http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html
检查 http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html
Also here in SO is a more detailed answer to this topic:
同样在这里,SO 是对这个主题的更详细的回答:
https://stackoverflow.com/questions/48249/java-embedding-a-web-browser-pane
https://stackoverflow.com/questions/48249/java-embedding-a-web-browser-pane
回答by coobird
Lobois a Java web browser which can be embedded into Swing applications.
Lobo是一种 Java Web 浏览器,可以嵌入到 Swing 应用程序中。
It supports HTML 4, CSS 2, and Javascript, which is more up-to-date compared to the JEditorPane
which only supports HTML 3.2.
它支持 HTML 4、CSS 2 和 Javascript,与JEditorPane
仅支持 HTML 3.2 的相比,它更加最新。
For some ideas on what is possible, the Lobo Browser API documentationshould provide an idea of what is possible to do with Lobo. In particular, the org.lobobrowser.gui
has a BrowserPanel
class which is a subclass of JPanel
, so it can be directly embedded in Swing applications.
对于一些可能的想法,Lobo 浏览器 API 文档应该提供关于 Lobo 可以做什么的想法。特别是,org.lobobrowser.gui
有一个BrowserPanel
类是 的子类JPanel
,因此可以直接嵌入到 Swing 应用程序中。
For example, the BrowserPanel.navigate
method can be used to jump to web pages, and there are many Listener
s which can capture events which occur in the browser.
例如,该BrowserPanel.navigate
方法可以用于跳转到网页,并且Listener
可以捕获浏览器中发生的事件的s有很多。
回答by Vladimir
You could try JxBrowser library: http://www.teamdev.com/jxbrowser/features/
你可以试试 JxBrowser 库:http: //www.teamdev.com/jxbrowser/features/
For example to embed Mozilla browser into your Java Swing application you just need to do the following code:
例如,要将 Mozilla 浏览器嵌入到您的 Java Swing 应用程序中,您只需执行以下代码:
Browser browser = BrowserFactory.createBrowser(BrowserType.Mozilla);
JFrame frame = new JFrame();
frame.add(browser.getComponent(), BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.navigate("http://www.google.com");
回答by Christopher Deckers
You could also try the JWebBrowser from DJ Native Swing: http://djproject.sourceforge.net/ns
您也可以尝试来自 DJ Native Swing 的 JWebBrowser:http://djproject.sourceforge.net/ns