Ajout de la limite de caractère demandé pour lorsque l'utilisateur ajoute
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
import javax.swing.text.*;
|
||||||
|
|
||||||
|
public class LimiteContenu extends PlainDocument {
|
||||||
|
private int limite;
|
||||||
|
|
||||||
|
public LimiteContenu(int limite) {
|
||||||
|
this.limite = limite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertString(int offset, String str, AttributeSet attr)
|
||||||
|
throws BadLocationException {
|
||||||
|
if (str == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((getLength() + str.length()) <= limite) {
|
||||||
|
super.insertString(offset, str, attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user