Deselect selected text in 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 ? 回答1: Text selection is temporaray and contiguous. You can't unselect some text in the middle of a larger string of selected text. Maybe you are talking about highlighting. Check out the API for getHighlighter(). You can add/remove highlights and specify the start/end