Java Swing How to - Resolve External resources for JEditorPane








Question

We would like to know how to resolve External resources for JEditorPane.

Answer

import java.awt.Dimension;
import java.io.File;
/*from  www.j  a v a2 s  .co  m*/
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

public class Main {

  public static void main(String[] args) throws Exception {
    File f = new File("index.html");
    JEditorPane jep = new JEditorPane(f.toURI().toURL());

    JScrollPane sp = new JScrollPane(jep);
    sp.setPreferredSize(new Dimension(400, 200));

    JOptionPane.showMessageDialog(null, sp);
  }
}