更新时间:2023-10-12 14:31:52
使用PlainDocument设置最大限制。这是一个粗略的草图:
Use PlainDocument to set the max limit. Here is a rough sketch :
public class JTextFieldLimit extends PlainDocument {
public void insertString( int offset, String str, AttributeSet attr ) throws BadLocationException {
//put yoyr max length validation logic
super.insertString(offset, str, attr);
}
}