limitedstyleddocument.java

来自「初期JAVA学习非常有用的资料。帮助深入了解API。特别是Applet。」· Java 代码 · 共 25 行

JAVA
25
字号
import javax.swing.*; import javax.swing.text.*; import java.awt.Toolkit;public class LimitedStyledDocument extends DefaultStyledDocument {    int maxCharacters;    public LimitedStyledDocument(int maxChars) {        maxCharacters = maxChars;    }    public void insertString(int offs, String str, AttributeSet a)         throws BadLocationException {        //This rejects the entire insertion if it would make        //the contents too long. Another option would be        //to truncate the inserted string so the contents        //would be exactly maxCharacters in length.        if ((getLength() + str.length()) <= maxCharacters)            super.insertString(offs, str, a);        else            Toolkit.getDefaultToolkit().beep();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?