java JTextArea 中的不同文本颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10391670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:51:25  来源:igfitidea点击:

Different text color in a JTextArea

javaswing

提问by Wassim Sboui

Is it possible to have different rows in different colors in a textarea? Have you an example for that?

是否可以在 textarea 中有不同颜色的不同行?你有这样的例子吗?

回答by Jeffrey

Not with a JTextArea. You can, however, use a JTextPanewhich allows for attributes to be applied to text. If you want examples, take a look at the Text Component Tutorial.

不带JTextArea. 但是,您可以使用JTextPane允许将属性应用于文本的 a。如果您需要示例,请查看文本组件教程