public void insertString(int offs,
String str,
AttributeSet atts) throws BadLocationException {
int length = getLength();
String newtext = null;
// is their already a number in the document?
if( length > 0 )
{
// if so, insert the string
String text1 = getText(0, offs );
String text2 = getText(offs, length - offs );
newtext = text1 + str + text2;
}
else
{
// document is empty, so take just the new string
newtext = str;
}
try {
// test wether its pasrable
Double.parseDouble( newtext );
}
catch( NumberFormatException e )
{
// it will not be a number if we insert the string
return;
}
super.insertString(offs, str, atts);
}
|