SAE21_2024/Sudoku/JTextFieldCharLimit.java

18 lines
511 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;
public class JTextFieldCharLimit extends PlainDocument{
private int limit;
public JTextFieldCharLimit(int limit){
this.limit = limit;
}
public void insertString(int offset, String str, AttributeSet set) throws BadLocationException{
if (str == null){
return;
} else if ((getLength() + str.length() - getLength()) <= limit){
super.insertString(offset, str, set);
}
}
}