您必须提供类型,并获取资源。就这样。我测试过的示例,但是不确定格式。希望能帮助到你:
import java.io.IOException;import javax.swing.JEditorPane;import javax.swing.Jframe;public class Test extends Jframe { public static void main(String[] args) throws Exception { Test.createAndShowGUI(); } private static void createAndShowGUI() throws IOException { Jframe.setDefaultLookAndFeelDecorated(true); Jframe frame = new Jframe("HelloWorldSwing"); frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); String imgsrc = Test.class.getClassLoader().getSystemResource("a.jpg").toString(); frame.getContentPane().add(new JEditorPane("text/html", "<html><img src='"+imgsrc+"' width=200height=200></img>")); frame.pack(); frame.setVisible(true); }}


