mydocument.java
来自「用eclipse做地图书管理系统」· Java 代码 · 共 29 行
JAVA
29 行
package com.wsy.util;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
public class MyDocument extends PlainDocument{
int maxLength =10;
public MyDocument(int newMaxLength){
super();
maxLength = newMaxLength;
}
public MyDocument(){
this(10);
}
//重载父类的insertString函数
public void insertString(int offset, String str, AttributeSet a)
throws BadLocationException {
if (getLength() + str.length() > maxLength) {//这里假定你的限制长度为10
return;
} else {
super.insertString(offset, str, a);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?