Java - 在 Jframe 中显示网页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18992547/
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
Java - Showing a Webpage In Jframe
提问by Oak
I have just recently added a update log to my game. I am using tumblr to show the update news. I used simple code (Listed Below) to show it but when I run it it looks nothing like the original tumblr!
我最近刚刚在我的游戏中添加了更新日志。我正在使用 tumblr 来显示更新新闻。我使用简单的代码(下面列出)来显示它,但是当我运行它时,它看起来与原来的 tumblr 完全不同!
package javaapplication32;
import javax.swing.*;
public class GetWebPage {
public static void main(String args[]) throws Exception {
JEditorPane website = new JEditorPane("http://smo-gram.tumblr.com/");
website.setEditable(false);
JFrame frame = new JFrame("Google");
frame.add(new JScrollPane(website));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
}
}
采纳答案by DeadlyFugu
There's a few other options available. If you need HTML5 support, switch over to JavaFX (It's way better than Swing IMO). There's also a HTML4/CSS2 renderer available for Swing called Cobra, and it seems pretty good. Another option would be Frostwire JWebBrowser, if you don't mind including native code, it seems to give you full HTML5 and CSS3 in Swing.
还有一些其他选项可用。如果您需要 HTML5 支持,请切换到 JavaFX(它比 Swing IMO 好得多)。还有一个名为 Cobra 的可用于 Swing 的 HTML4/CSS2 渲染器,它看起来相当不错。另一种选择是Frostwire JWebBrowser,如果您不介意包含本机代码,它似乎在 Swing 中为您提供完整的 HTML5 和 CSS3。
回答by Paul Vargas
Remove the call of pack()
method. In another way, do not expect much of HTML Swing. Supports up to HTML 3.2 (http://www.w3.org/TR/REC-html32.html).
删除pack()
方法的调用。换句话说,不要对 HTML Swing 寄予厚望。最高支持 HTML 3.2 ( http://www.w3.org/TR/REC-html32.html)。
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class GetWebPage {
public static void main(String args[]) throws Exception {
JEditorPane website = new JEditorPane("http://smo-gram.tumblr.com/");
website.setEditable(false);
JFrame frame = new JFrame("Google");
frame.add(new JScrollPane(website));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setVisible(true);
}
}
回答by Jesse Hernandez
Check out http://java.dzone.com/articles/web-browser-your-java-swing.
查看http://java.dzone.com/articles/web-browser-your-java-swing。
JxBrowser lets you display any webpage,by embedding a browser into your swing application.
JxBrowser 允许您通过将浏览器嵌入到您的 Swing 应用程序中来显示任何网页。