用于聊天室的JTextPane或JEditorPane

时间:2011-12-05 16:30:35

标签: java swing jtextpane jeditorpane chatroom

我必须像这样做一个聊天室:

enter image description here

显示的信息还必须显示笑脸和myst可以像Skype一样复制/粘贴的所有内容。

我不知道在JEditor和JTextpane之间做出选择。我尝试过两次遇到以下困难:

JEditorPane:

  • 复制/过去,可以显示表情符号并复制粘贴它们。
  • 当我将内容设置为text / html
  • 时,我无法设置消息的leftIndent

JTextPane:

  • 我可以设置leftIndent
  • 当我将文本内容设置为html时,无法复制/粘贴笑脸图标。
  • 无法在消息中显示笑脸

也许我错了,我不知道足够的事情,所以我想听听你的意见:)

非常感谢。

此致

2 个答案:

答案 0 :(得分:2)

使用JTextPane。将内容类型设置为text / html。并通过setText();

放置适当的html

这是关于本地图像的 http://java-sl.com/tip_local_images.html

这一个关于微笑 http://java-sl.com/tip_autoreplace_smiles.html

答案 1 :(得分:2)

(除了StanislavL的回答。)至少在Java 1.7中,leftindent适用于JTextPane:

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