I’ve been wondering if for example:
JTextPane chatTextArea = new JTextPane();
s.replaceAll(":\\)", emoticon());
public String emoticon(){
chatTextArea.insertIcon(new ImageIcon(ChatFrame.class.getResource("/smile.png")));
return "`";
}
can put a picture and a “`” everywhere “:)” is found. When I run it like this if s contains a “:)” then the whole s gets replaced just by the icon.
Is there a way to do it?
Here is a small example I made (+1 to @StanislavL for the original), simply uses
DocumentListenerand checks when a matching sequence for an emoticon is entered and replaces it with appropriate image:NB: SPACE must be pressed or another character/emoticon typed to show image
References: