Here you can find the source of writeImage(final JTextPane jtPane, final ImageIcon msg)
public static void writeImage(final JTextPane jtPane, final ImageIcon msg)
//package com.java2s; //License from project: Open Source License import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JTextPane; import javax.swing.SwingUtilities; public class Main { public static void writeImage(final JTextPane jtPane, final ImageIcon msg) { SwingUtilities.invokeLater(new Runnable() { @Override//from ww w . j a va 2 s . c om public void run() { Image scaleImage = msg.getImage().getScaledInstance(75, 75, Image.SCALE_DEFAULT); msg.setImage(scaleImage); jtPane.insertIcon(msg); } }); } public static void writeImage(final JTextPane jtPane, final ImageIcon msg, final int size) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Image scaleImage = msg.getImage().getScaledInstance(size, size, Image.SCALE_DEFAULT); msg.setImage(scaleImage); jtPane.insertIcon(msg); } }); } }