Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextField and keyPressed Event

Status
Not open for further replies.

Watts

Programmer
Jan 18, 2001
80
US
I am using the CaretPosition of a TextField in order to switch fields based on a keyPressed event. The problem is that this event is not behaving consistantly. Sometimes the event is handled before the character appears (which is what I want) and sometime the event is handled after the character is added (not what i want). When the later happens my keyPressed event doesn't switch to the next field causing a serious problem.

Does anyone know how to force this keyPressed event to occurs before the character is added to the TextField?
 
This might work:

public void keyPressed(KeyEvent e)
{
int c = tf.getCaretPosition();

if(c>=10)
{
tf2.requestFocus();
}
}
 
That is exactly what I am doing Vepo. My problem is that is Visual Cafe it handles the keyPressed event differently than Internet Explorer. Your code works great in Cafe but when I try to run it on IE the character appears and then the focus is shifted.
 
Sorry, I didn't know that you are coding an applet... maybe someone who knows more about applets can help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top