Java JTextPane-关闭最后一个样式
我想给JTextPane中的一些关键字上色。但是我不想在这些话之后保持同样的风格Java JTextPane-关闭最后一个样式,java,swing,jtextpane,Java,Swing,Jtextpane,我想给JTextPane中的一些关键字上色。但是我不想在这些话之后保持同样的风格 while (regexMatcher.find()){ int start = regexMatcher.start(); int end = regexMatcher.end(); document.setCharacterAttributes(start, end-start, style, false); } 但是,
while (regexMatcher.find()){
int start = regexMatcher.start();
int end = regexMatcher.end();
document.setCharacterAttributes(start, end-start, style, false);
}
但是,当我在最后一个字符之后单击并键入具有相同样式但希望更改回默认值的内容时,它会起作用
如何解决此问题?您可以将
CaretChangeListener
添加到JTextPane
中。在每次插入符号更新时,应清除安装在JTextPane
中的编辑器的输入属性
MutableAttributeSet inputAttributes=((StyledEditorKit)pane.getEditorKit()).getInputAttributes();
//remove all the unwanted style attributes