1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
public class testDocument extends javax.swing.text.PlainDocument {
private javax.swing.JTextField p_componentReference=null;
private int p_max=30;
public testDocument(javax.swing.JTextField a,int max) {
p_componentReference=a;
p_max=max;
}
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
int longTotale = str.length()+p_componentReference.getText().length();
if (p_max<=longTotale)
{
super.insertString(offs, str, a);
}
}
} |
Partager