首页javajeditorpaneJava Swing - 如何把JEditorPane放在JScrollPane中

Java Swing - 如何把JEditorPane放在JScrollPane中

我们想知道如何把JEditorPane放在JScrollPane中。
import java.io.IOException;

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

public class Main extends JFrame {

  public static void main(String args[]) {
    Main e = new Main();
    e.setVisible(true);
  }

  public Main() {

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

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

    final JScrollPane scrollPane = new JScrollPane(web);
    getContentPane().add(scrollPane);
    this.setBounds(0, 0, 200, 200);

  }

}