Name: rk38400 Date: 05/20/98 Registering a keyListener for the JTextField component, and defining the keyTyped method for that interface one can quickly see that the keyTyped event is fired BEFORE the char is added to the JTextField. It should be called after the character has been added. This is still the case under Swing-1.0.2. The following simple example shows this. /* ---------------------- */ import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; public class test extends JFrame { JTextField tf; public test() { getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT)); tf = new JTextField(30); getContentPane().add(tf); tf.addKeyListener(new keyboardHandler()); setSize(200,100); } class keyboardHandler extends KeyAdapter { public void keyTyped(KeyEvent event) { System.out.println(tf.getText().length()); } } public static void main(String [] args) { (new test()).show(); } } (Review ID: 30689) ======================================================================
|