JTextPane or JEditorPane for a Chatroom

空扰寡人 提交于 2020-01-15 04:38:04

问题


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>


来源:https://stackoverflow.com/questions/8388489/jtextpane-or-jeditorpane-for-a-chatroom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!