JTextPane or JEditorPane for a Chatroom

2019-07-13 13:23发布

问题:

I have to make a chatroom like this one :

The message displayed also have to show the smileys and everything myst be copy/pastable like in Skype.

I don't know what to choose between the JEditor and JTextpane. I tried both I faced the following difficulties :

JEditorPane :

  • Copy/Pastable, can show the smileys and copy paste them.
  • I can't set the leftIndent of the message when I set the content to text/html

JTextPane :

  • I can set the leftIndent
  • Can't copy/paste the smiley Icons when I set the text content to html.
  • Can't display the smiley in the message

Maybe I'm wrong and I don;t know enough things so I would like to hear your opinions :)

Thank you very much.

Regards

回答1:

Use JTextPane. Set content type to text/html. And place appropriate html via setText();

That's about local images http://java-sl.com/tip_local_images.html

And this one about smiles http://java-sl.com/tip_autoreplace_smiles.html



回答2:

(Additional to the answer of StanislavL.) At least in Java 1.7 leftindent works for JTextPane:

<html>
  <head>
    <style type='text/css'>
        p { text-indent: 20px; }
    </style>
  </head>
  <body>
    <p style="margin-top: 0">
    The text.
    </p>
  </body>
</html>