1 package net.sf.panoptes.swing.propeditors; 2 3 import javax.swing.text.AttributeSet ; 4 import javax.swing.text.BadLocationException ; 5 import javax.swing.text.PlainDocument ; 6 7 public class IntegerDocument extends PlainDocument { 8 9 public void insertString(int i, String s, AttributeSet attributes) 10 throws BadLocationException { 11 12 super.insertString(i, s, attributes); 13 if (s != null && (!s.equals("-") || i != 0 || s.length() >= 2)) { 14 try { 15 Integer.parseInt(getText(0, getLength())); 16 } 17 catch (NumberFormatException e) { 18 remove(i, s.length()); 19 } 20 } 21 } 22 23 } 24 | Popular Tags |