我试图限制在 JTextField 中输入的字符数......为此我创建了一个这样的类:
class JTextFieldLimiter extends PlainDocument
{
private int limit;
JTextFieldLimiter(int limit)
{
super();
this.limit= limit;
}
public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException {
if (str == null)
return;
if ((getLength() + str.length()) <= limit) {
super.insertString(offset, str, attr);
}
}
}
我认为这必须正常工作,但编译器显示错误,它说:
cannot find symbol: method insertString(int,java.lang.String,javax.print.attribute.Attributeset)
location:class javax.swing.text.PlainDocument
super.insertString(offset,str,(AttributeSet) attr);
^
代码有什么问题?