1 43 44 package org.jfree.ui; 45 46 import javax.swing.text.AttributeSet ; 47 import javax.swing.text.BadLocationException ; 48 import javax.swing.text.PlainDocument ; 49 50 55 public class IntegerDocument extends PlainDocument { 56 57 66 public void insertString(final int i, final String s, final AttributeSet attributes) 67 throws BadLocationException { 68 69 super.insertString(i, s, attributes); 70 if (s != null && (!s.equals("-") || i != 0 || s.length() >= 2)) { 71 try { 72 Integer.parseInt(getText(0, getLength())); 73 } 74 catch (NumberFormatException e) { 75 remove(i, s.length()); 76 } 77 } 78 } 79 80 } 81 | Popular Tags |