File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Automatic Tab Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Automatic Tab" Watch "Automatic Tab" New topic

Automatic Tab

Rocky Summers
Ranch Hand

Joined: Nov 07, 2003
Posts: 66
hello ranchers!
just wondering.... how do i do an automatic tab? for example: i have 3 text fields.. on the first text field, if i enter 3 characters, it automatically tabs to the second textfield.. and if in the 2nd txtfield, if i enter 3 characters, it automatically tabs to the third txtfield.. and on the third txtfield, if i enter more than 7 characters, it won't allow it to add more.. is there any way to do this?
please let me know... thank you!
~ rockster
saager mhatre
Ranch Hand

Joined: Dec 20, 2000
Posts: 61
This shouldn't be too hard. You'll have to set up DocumentListeners for the Document models of the three JTextComponents in question and monitor the events for changes in length of entered text. Once a component reaches its threshold, simply call the suitable requestFocus() method on the component you want to move to!
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
If you want to limit the content of the textfields to a number of chars, calling methods(*) on the Document object from within a DocumentListener might deadlock. The approach given in the Java Tutorial is implementing a document filter
(*) Those that modify the text
[ January 31, 2004: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link:
subject: Automatic Tab
jQuery in Action, 3rd edition