在JTextPane中取消选择选定的文本 [英] Deselect selected text in JTextPane

查看:106
本文介绍了在JTextPane中取消选择选定的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编辑器,我要在其中检查所选文本是否不包含某些单词.如果它包含那些特定的单词,那么我需要取消选择用户所做的选择. JTextPane有什么方法可以做到这一点?

I have an editor in which I want to check that selected text will not contain some words. If it contains those particular words, then I need to deselect the selection made by user. Is there any way to do that in JTextPane?

推荐答案

文本选择是临时的并且是连续的.您无法取消选择较大文本字符串中的某些文本.

Text selection is temporaray and contiguous. You can't unselect some text in the middle of a larger string of selected text.

也许您正在谈论突出显示.检出getHighlighter()的API.您可以添加/删除突出显示并指定每个突出显示的开始/结束偏移量.

Maybe you are talking about highlighting. Check out the API for getHighlighter(). You can add/remove highlights and specify the start/end offsets of each highlight.

这篇关于在JTextPane中取消选择选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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