Java Swing - 如何對(duì)齊JEditorPane中文本中的圖像
我們想知道如何對(duì)齊JEditorPane中文本中的圖像。
import java.awt.BorderLayout;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class Main extends JFrame {
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationByPlatform(true);
JEditorPane editPane = new JEditorPane();
JScrollPane scrollPane = new JScrollPane(editPane);
editPane.setContentType("text/html");
editPane
.setText("<html><p style = \"text-align:center;\">Hello there, How you doing ?<img src = "
+ "\"http://eska-fuses.cn/style/download.png"
+ "\" alt = \"pic\" width = \"15\" height = \"15\" />test test test"
+ "<br />I hope this is what you wanted!! "
+ "<img src = \"http://eska-fuses.cn/style/download.png"
+ "\" alt = \"pic\" width = \"15\" height = \"15\" /> this is a test.</p></html>\n");
add(scrollPane, BorderLayout.CENTER);
setSize(400, 300);
setVisible(true);
}
public static void main(String... args) {
new Main();
}
}