01: // DoubleTextField.java
02: // $Id: DoubleTextField.java,v 1.3 2000/08/16 21:37:31 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigadmin.widgets;
07:
08: import java.awt.event.KeyAdapter;
09: import java.awt.event.KeyEvent;
10:
11: import javax.swing.JTextField;
12:
13: /**
14: * A TextField that accepts only num char and '.'
15: * @version $Revision: 1.3 $
16: * @author Benoît Mahé (bmahe@w3.org)
17: */
18: public class DoubleTextField extends JTextField {
19:
20: protected void processComponentKeyEvent(KeyEvent ke) {
21: if (ke.getKeyCode() == KeyEvent.VK_DELETE
22: || ke.getKeyCode() == KeyEvent.VK_BACK_SPACE
23: || ke.getKeyCode() == KeyEvent.VK_UP
24: || ke.getKeyCode() == KeyEvent.VK_DOWN
25: || ke.getKeyCode() == KeyEvent.VK_LEFT
26: || ke.getKeyCode() == KeyEvent.VK_RIGHT)
27: super .processComponentKeyEvent(ke);
28: if (!(ke.getKeyChar() >= '0' && ke.getKeyChar() <= '9')
29: && (ke.getKeyChar() != '.') && ke.getKeyChar() != ',') {
30: ke.consume();
31: } else {
32: super.processComponentKeyEvent(ke);
33: }
34: }
35:
36: }
|