SAE21_2024/Sudoku/JTextFieldCharLimit.java

19 lines
534 B
Java
Raw Normal View History

2024-04-30 02:12:14 +02:00
import javax.swing.text.PlainDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
2024-04-30 11:18:29 +02:00
public class JTextFieldCharLimit extends PlainDocument
{
private int max;
JTextFieldCharLimit(int max) {
super();
this.max = max;
}
public void insertString(int offset, String text, AttributeSet attr) throws BadLocationException {
if (text == null)
return;
if ((getLength() + text.length()) <= max) {
super.insertString(offset, text, attr);
}
}
2024-04-30 02:12:14 +02:00
}