KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > panoptes > swing > propeditors > IntegerDocument


1 package net.sf.panoptes.swing.propeditors;
2
3 import javax.swing.text.AttributeSet JavaDoc;
4 import javax.swing.text.BadLocationException JavaDoc;
5 import javax.swing.text.PlainDocument JavaDoc;
6
7 public class IntegerDocument extends PlainDocument JavaDoc {
8
9     public void insertString(int i, String JavaDoc s, AttributeSet JavaDoc attributes)
10         throws BadLocationException JavaDoc {
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 JavaDoc e) {
18                 remove(i, s.length());
19             }
20         }
21     }
22
23 }
24
Popular Tags