Java Swing - 如何在JEditorPane上顯示圖像
我們想知道如何在JEditorPane上顯示圖像。
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
public class Main extends JFrame {
public static void main(String[] args) throws Exception {
Main.createAndShowGUI();
}
private static void createAndShowGUI() throws IOException {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String imgsrc = Main.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);
}
}