Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to process TAB Key on JTextField, when data coming from Scanner?

843805Feb 6 2007 — edited Feb 7 2007
We have a small GUI application used to read and process the barcode information. We do read/scan 13 digit product barcodes thru a keyboard wedge scanner.

We have 2 text fields (cursor is at the zero position in the first field by default). So what we need to do is,
Once we scan a barcode thru Scanner, we need to make our app to write the first 6 digits in first text field and the next 7 digits to the second text field.

How can I do that?

I tried this approach, but it did not work.

Ex: In coming scanner data is: 1234567891011

Tried to process the data as : 123456[i][TAB[/i]]7891011

While writing, I could check the first text field�s text length and if it is 6, then try to process a TAB char manually (created a KeyEvent and dispatched it) and leave it.
I thought KeyBoard Manager skips to next text field and process the rest of the data.

KeyEvent tab_pressed = new KeyEvent( com , KeyEvent.KEY_PRESSED , System.currentTimeMillis() , 0 ,  KeyEvent.VK_TAB ,  KeyEvent.CHAR_UNDEFINED );

//Here com is the first text field
com.dispatchEvent(tab_pressed );

KeyEvent tab_released = new KeyEvent( FocusManager.getCurrentManager().getFocusOwner() , KeyEvent.KEY_RELEASED , System.currentTimeMillis() ,  0 ,  KeyEvent.VK_TAB , KeyEvent.CHAR_UNDEFINED );

FocusManager.getCurrentManager().getFocusOwner().dispatchEvent(tab_released );
Results:
This works fine when I type the barcode thru KeyBoard. Means, if I type 123456 thru Key Board on first text field, as long as I typed 6th number, it automatically jumps to the next field.

Where as, if the data is coming from the scanner, It jumps to the next field BUT the data writing is not consistent. I.e. some times the whole 13 digits entered in to the first field , some times 12 go in first field and 1 go to the second fields.

It SHOULD do like 6 digits go to first field and next 7 go to the second field.

Some how TAB is not processing FAST Enogth as the Scanners incoming data.

Where is it going wrong? Am I missing any thing?

Any help would be appreciated.

Message was edited by:
kvally74
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2007
Added on Feb 6 2007
4 comments
267 views