首页javajeditorpaneJava Swing - 如何在JEditorPane中显示网页

Java Swing - 如何在JEditorPane中显示网页

我们想知道如何在JEditorPane中显示网页。
import java.io.IOException;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

public class Main {

  public static void main(String[] args) {

    JEditorPane jep = new JEditorPane();
    jep.setEditable(false);

    try {
      jep.setPage("http://www.google.com");
    } catch (IOException e) {
      jep.setContentType("text/html");
      jep.setText("<html>Could not load http://www.google.com </html>");
    }

    JScrollPane scrollPane = new JScrollPane(jep);
    JFrame f = new JFrame();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scrollPane);
    f.setSize(512, 342);
    f.show();

  }

}