简体   繁体   English

JTextArea 不显示本机字体表情符号

[英]JTextArea doesn't show native-font emoticons

When I print a text that contain emoticons using standard output, the emoticons are shown (pic 1).当我使用标准输出打印包含表情符号的文本时,会显示表情符号(图 1)。 But when I display the text in JTextArea, the emoticons appear as unidentified chars (pic2).但是当我在 JTextArea 中显示文本时,表情符号显示为未识别的字符 (pic2)。 How to solve this?如何解决这个问题?

I'm on OS X & I used the same font for JTextArea as with other editors.我在 OS X 上,我对 JTextArea 使用了与其他编辑器相同的字体。

EDIT: I DON'T want to put predefined image emoticons.编辑:我不想放置预定义的图像表情符号。 Rather I want to display the emoticons that are native with fonts.相反,我想显示带有字体的本机表情符号。 So if I write in any text editor :), I will get an emoticon because the font already has this.因此,如果我在任何文本编辑器中书写 :),我都会得到一个表情符号,因为字体已经有了这个表情符号。 I want this to work in JTextArea.我希望它在 JTextArea 中工作。

在此处输入图片说明

在此处输入图片说明

I'm assuming the string you're rendering is just plain text that contains Unicode emoticon characters from the miscellaneous symbols range or some similar block - for example, the frowny face is U+2639 ?我假设您渲染的字符串只是纯文本,其中包含来自杂项符号范围或某些类似块的 Unicode 图释字符 - 例如,皱眉的脸是U+2639 If that's not the case, you can disregard the rest of this answer (and consider updating your question to specify what it is you are doing).如果情况并非如此,您可以忽略此答案的其余部分(并考虑更新您的问题以指定您做什么)。

You've said "it works on the standard output but doesn't work in a JTextArea" - but it looks to me like a different font is being used in your standard output console view than in the JTextArea (look at the "i" character in "Maggie" as an example of how the fonts are different).您已经说过“它适用于标准输出,但不适用于 JTextArea” - 但在我看来,标准输出控制台视图中使用的字体与 JTextArea 中使用的字体不同(查看“i” “Maggie”中的字符作为字体如何不同的示例)。

It looks as though the font that is being used to render the characters in the console window "knows" how to draw a U+2639, but the font being used in the JTextArea doesn't "know" how to render the character.看起来好像用于在控制台窗口中呈现字符的字体“知道”如何绘制 U+2639,但 JTextArea 中使用的字体不“知道”如何呈现字符。 The "unidentified chars" that you're seeing are colloquially known as "tofu": whenever a font doesn't know how to draw a character, it draws the " white square " character instead.您看到的“未识别字符”通俗地称为“豆腐”:每当字体不知道如何绘制字符时,它就会绘制“白色方块”字符。 Try the API canDisplay() method for figuring out if a specific font "knows" how to display a specific character.尝试 API canDisplay()方法以确定特定字体是否“知道”如何显示特定字符​​。

Exactly what font are you setting on the JTextArea and how?您在 JTextArea 上究竟设置了什么字体以及如何设置?
Consider posting an SSCCE - I do have access to an OS X environment at the moment so I might be able to help;考虑发布SSCCE - 我目前确实可以访问 OS X 环境,所以我可以提供帮助; and of course there's a hojillion other people that can probably help you out to if they could see clearly what you're doing.当然,如果他们能清楚地看到你在做什么,那么还有很多其他人可能会帮助你。

Use JTextPane.使用 JTextPane。 Set content type to text/html.将内容类型设置为 text/html。 And place appropriate html via setText();并通过 setText() 放置适当的 html;

That's about local images http://java-sl.com/tip_local_images.html那是关于本地图像http://java-sl.com/tip_local_images.html

And this one about smiles http://java-sl.com/tip_autoreplace_smiles.html这是关于微笑的http://java-sl.com/tip_autoreplace_smiles.html

试用此代码可能会帮助您一点链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM