如何在Java中为选定的文本设置颜色? [英] How to set Color for selected Text in java?

查看:154
本文介绍了如何在Java中为选定的文本设置颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人帮助您仅设置所选文本的颜色...我已经创建了一个简单文本编辑器...但是,我无法设置所选文本内容的颜色...一次,我已经选择了颜色会影响整个文本区域,而不是选定区域.

Please any one help for set the color for selected text only... I has Create a Simple Text Editor... But, I can't set the color for selected text contents... once ,I has select the color it will affect the whole text area instead of selected area.

请帮助任何人,

预先感谢.

for Example : 

现在我仅选择Kumar.因此,将仅为所选文本选择颜色..但是,我的问题是也更改了未选中文本的颜色.

Now I select the Kumar only..So,will select the color for that selected text only..But,my problem is change the color for unselected text also..

如何解决???????

How to resolve it???????

推荐答案

您使用什么组件显示文本? 如果它是JTextArea,则不可能. 您需要一个允许使用不同样式的组件.例如,JTextPane中的StyledDocument. 有关更多信息,请参见如何使用编辑器窗格和文本窗格

With what component do you display your text? If it is JTextArea, then it is not possible. You need a component that allows different styles. For example a StyledDocument in a JTextPane. For more information see How to Use Editor Panes and Text Panes

这篇关于如何在Java中为选定的文本设置颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆