Java - Showing a Webpage In Jframe

匆匆过客 提交于 2019-12-10 11:38:19

问题


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!

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();
    }

}

回答1:


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.




回答2:


Check out http://java.dzone.com/articles/web-browser-your-java-swing.

JxBrowser lets you display any webpage,by embedding a browser into your swing application.




回答3:


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).

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);
    }
}


来源:https://stackoverflow.com/questions/18992547/java-showing-a-webpage-in-jframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!