package com.aratana.ui.fields;
import java.awt.ComponentOrientation;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
@SuppressWarnings("serial")
public class NumberField extends BasicField<Long> {
public NumberField() {
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
setDocument(new PlainDocument() {
@Override
public void insertString(final int offs, String str, final AttributeSet a) throws BadLocationException {
str = str.replaceAll("[^0-9]", "");
super.insertString(offs, (getMax() > 0 && str.length() + NumberField.this.getText().length() > getMax() ? str.substring(0, getMax() - NumberField.this.getText().length()) : str).toUpperCase(), a);
}
});
}
}
|