且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在java netbeans中为JTextField设置最大字符长度

更新时间: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);
  }
}