2
我正在写一个DocumentFilter,它将用顶端逻辑符号输入到JTextField中的所有单词“top”替换掉。JTextField中的Stange unicode行为
使用此代码是好的,但是这很烦人的用户重新输入他们的空间,他们可以做的,在同一行
temp.replaceAll("\\btop\\b", "\\\u22A4");
文本继续使用此代码,并在加与更换空间使顶部符号和JTextField中的所有文本时微微用户继续输入则文云的下面,并开始一个新行
temp.replaceAll("\\btop\\b", "\\\u22A4 ");
谁能请解释这种现象,并希望被推高提供解决方案?谢谢。
@Override
public void replace(FilterBypass fb, int offset, int length,
String string, AttributeSet attr)
throws BadLocationException {
int totalLength = fb.getDocument().getLength();
String temp = fb.getDocument().getText(0, totalLength);
temp = temp.replaceAll("\\btop\\b", "\\\u22A4"); //needs space
super.remove(fb, 0, totalLength);
super.insertString(fb, 0, temp, attr);
super.replace(fb, offset, length, string, attr);
}
太棒了,谢谢。 –