How to add images in JTextPane?

Suhail Ahamed picture Suhail Ahamed · Apr 3, 2012 · Viewed 10.8k times · Source

I want to give the user the facility to copy and paste Images in JTextPane. Please help me.

Answer

Mikle Garin picture Mikle Garin · Apr 3, 2012

There is an easy way to add an image:

JTextPane pane = new JTextPane ();
pane.insertIcon ( new ImageIcon ( "/path/to/image.png" ) );

But there is no simple way to copy an image from the pane, since it cannot be selected and cannot be easily located in the pane document.