-1
如何將多個圖像添加到JTextPane中?在JTextpane中插入兩個圖標
我有以下代碼只附加第一個圖像。
Image img = null;
Image img2 = null;
try {
img = ImageIO.read(new File(Main.imagePath + "1.jpg"));
img2 = ImageIO.read(new File(Main.imagePath + "2.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
Image simg = img.getScaledInstance(310, 90, Image.SCALE_SMOOTH);
Image simg2 = img2.getScaledInstance(310, 90, Image.SCALE_SMOOTH);
Main.ScreenText.insertIcon (new ImageIcon(simg));
Main.ScreenText.insertIcon (new ImageIcon(simg2));
ScreenText是一個JTextPane。
我想這和它工作得很好。我發現無法看到第二張圖像的唯一潛在原因是容器太小而不在屏幕上時,這可能是您的問題? – Peter