Auto-shift of focus between JTextFields
Greetings.
I have an array of 50 JTextFields which I restricted to a four-character entry limit. The limit works just fine, but I would like the focus to shift to the next JTextField when the limit is reached. Currently, I'm watching for the limit via an extended PlainDocument called CharLimitDocument. (*code included below) I know that Java offers the function FocusManager.focusNextComponent(Component aComp), but I'm not sure how to retrieve the current component. Can anyone help?
Thanks in advance,
Liz
*CharLimitDocument Code
import javax.swing.text.*;
import java.awt.*;
//This class overloads the Document so that a JTextField can be designed to accept only a specific number of characters.
class CharLimitDocument extends PlainDocument
{
private int limit;
public CharLimitDocument(int limit)
{ this.limit = limit; }
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
{
if((str.length() + getLength()) <= limit)
{super.insertString(offs, str, a);}
else
{Toolkit.getDefaultToolkit().beep();}
}
}//end class CharLimitDocument

