我試圖限制JTextField中輸入的字符數的字符數......爲此我創建這樣的一個類:無法設置限制的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);
^
代碼有什麼問題?
你的開啓和關閉大括號在你的實際代碼中是否正確排列?你在這段代碼中遺漏了一個右大括號... – irrelephant 2010-12-23 08:29:38
對不起......實際代碼很好..... – sasidhar 2010-12-23 08:34:55