Oak
Oak

Reputation: 518

Java - Showing a Webpage In Jframe

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

}

Upvotes: 2

Views: 15677

Answers (3)

DeadlyFugu
DeadlyFugu

Reputation: 152

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.

Upvotes: 1

Jesse Hernandez
Jesse Hernandez

Reputation: 317

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.

Upvotes: 3

Paul Vargas
Paul Vargas

Reputation: 42020

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

Upvotes: 1

Related Questions