从逻辑上看应该是没有什么问题。不过你的处理过于草率,我任务应该用截取:
public void insertString(int offset, String s, 
AttributeSet attributeSet) 
throws BadLocationException
{
.....
      if (s.length() >8) { //限制输入8字符
          s=s.substring(0,8); } 
super.insertString(newOffset, s,attributeSet);
}
.........
}
你所说的有问题是指什么?