Product Barcodes that has a TAB char embedded
We have a product barcodes, which have got TAB char embedded.
Example single Barcode: 14453405牋牋燩RX012
(Where first part is Product id, the space represents ASCII HT, Horizontal Tab, and the last part is Product Description)
In our JFrame we have 2 text fields side by side. So we put the cursor in first text field and read the bar code thru keyboard wedge scanner. (scanner writes the char data (keys) to the application, as the keys coming from the Key Board)
So expected the KeyBoard Manager write the product id, 14453405, in first Text Field and applies Tab char (So it would jump to the next text field) and write the description, PRX012, in the second Text Field.
We expected this result:
1st text field text:14453405
2nd text fieldtext:PRX012
But...
The TAB char applies (jumps to the next text field) OK, but NOT in the sequence as in the barcode.
What we are getting:(We scanned multiple times)
1st text field text:14453405PRX0
2nd text fieldtext:?b>12
1st text field text:14453405P 牋?br>2nd text fieldtext:RX012
1st text field text:14453405PRX 牋牋
2nd text fieldtext:012
...
As you see the results are not consistent.
We found that it DOES recognize and apply the TAB (It jumps to the next text field) but NOT in the sequence as in the barcode.
We believe, the problem is, The TAB character is NOT processing in the sequence as with other characters in the barcode.
Any help would be really appreciated.
Thanks
K
Note:
Programmatically we are not doing any handle mechanism.
Because the scanner writes the char data (char keys) to the application, as the Data coming from the Key Board.
So in Java, the KeyBoard manager should treat the data, key events, as they are coming from Key Board and process them.
If so, why the TAB char not processing in sequence ? Is there any 2nd thread handles the TAB ?
What do you say?
Results in other applications:
Scanner writes the barcode in Notepad as:
14453405PRX012
We assume it applied the Tab char CORRECTLY here.
In the Excel, scanner writes the barcode as:
14453405 (in first cell) and PRX012 (in the second cell)
We assume it applied the Tab char CORRECTLY here.
[2421 byte] By [
kvally74a] at [2007-11-26 18:07:12]

# 1
> If so, why the TAB char not processing in sequence ?
Don't know but you where given a suggestion on an easy way to fix this when you asked the question 4 days ago.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.
# 2
Camick, This is little different question to the previous one.
I have just 2 text fields on my JFrame. that's it. No listeners,special code,....nothing.
The question is straight forward.
In this case, By default, the scanner is giving xxxxx<tab>yyyyy . I am expecting the KeyBoard manager to process it properly.
I.e. xxxxxon first text field, Then TAB , then yyyyy on next text field.
But it does not.
Hope the question is clear.
Thanks lot
K
Message was edited by:
kvally74
# 3
> The question is straight forward.
And the answer is straight forward. The KeyEvents are coming in too fast for the system to handle them as you would expect. So characters are inserted into the first document before the focus transfer happens.
Maybe you can configure the scanner to slow down the rate at which the events are generated.
Otherwise, as I suggeste earlier, you can write a DocumentFilter that forwards characters from the first Document when it gets full to the second document (maybe 15 lines of code). Or you can wait another 4 days before trying to fix the problem.
> So there is nothing to write a SSCCE program (where it is not required).
The SSCCE is for us to see exactly what you are doing and see what is happening. Then if we want to try and find a solution we have code to start with.
If you wrote one you could see that this behaviour is easily replicated by using a Robot.
# 4
Camick
First We are trying to understand the exact problem.
And we are trying to make the product work as it is at Customer sites (as you suggested, maybe configuring the scanner to slow down the rate) Or some thing like that ,
With out any fix Or Product patch release (It's a big procedure! and Time matters!)
It is nothing like fixing it in 15 lines or wait for another 4 days problem
Hope you understand.
Off course, if nothing works, We would have a code fix.
Any other suggestions welcome!
Thanks
K
# 5
Can't you just read the input into a buffer and then read that into the fields?
# 6
Comick
>The KeyEvents are coming in too fast for the system to handle them as you would expect. So characters are inserted into the first document before the focus transfer happens.
Do you think this is SAME as in all JRE's. Or Do you think it might improve in latest JRE's (either 1.5 or 1.6 ...). Customer uses 1.4.2_xx.
Thanks for help.
> Can't you just read the input into a buffer and then read that into the fields?
May be not. Because it is a generic , Automatic Field and Some times they type the barcode and some times they use the Scanner.
Thanks
K
# 7
> Do you think this is SAME as in all JRE's. Or Do you think it might
> improve in latest JRE's (either 1.5 or 1.6 ...). Customer uses 1.4.2_xx.
I'm also using 1.4.2 but my guess is it would be a problem on later versions as well. Its easy to test using the following code.
I did the following test on my computer:
a) java OverflowDocumentFilter 0 // all text is in the first text field
b) java OverflowDocumentFilter 1 // most of the text in first, some in the second (varies each time)
c) java OverflowDocumentFilter 2 // text split correctly in first and second text fields
Don't know if its related to version or computer CPU or platform. But I suggest the only sure way to fix the problem is to slow down the rate at which events are generated.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class OverflowDocumentFilter extends DocumentFilter
{
private int maxCharacters;
private Document overflowDocument;
public OverflowDocumentFilter(int maxCharacters, Document overflowDocument)
{
this.maxCharacters = maxCharacters;
this.overflowDocument = overflowDocument;
}
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
throws BadLocationException
{
replace(fb, offs, 0, str, a);
}
public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
throws BadLocationException
{
super.replace(fb, offs, length, "", a);
// All the text can be added to this document
int totalLength = fb.getDocument().getLength() + str.length();
if (totalLength <= maxCharacters)
{
super.insertString(fb, offs, str, a);
return;
}
// Add the character to the overflow Document
if (str.length() == 1)
{
overflowDocument.insertString(overflowDocument.getLength(), str, a);
return;
}
// Some text in this document and some in the overflow Document
int index = maxCharacters - fb.getDocument().getLength();
String original = str.substring(0, index);
super.insertString(fb, offs, original, a);
String overflow = str.substring(index);
overflowDocument.insertString(overflowDocument.getLength(), overflow, a);
}
public static void main(String[] args)
throws Exception
{
JTextField textField1 = new JTextField(10);
JTextField textField2 = new JTextField(10);
AbstractDocument doc = (AbstractDocument)textField1.getDocument();
//doc.setDocumentFilter( new OverflowDocumentFilter(6, textField2.getDocument()) );
JPanel panel = new JPanel();
panel.add( textField1 );
panel.add( textField2 );
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.getContentPane().add(panel);
frame.pack();
frame.show();
Thread.sleep(2000);
Robot robot = new Robot();
robot.setAutoDelay( Integer.parseInt(args[0]) );
robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_C);
robot.keyPress(KeyEvent.VK_D);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_F);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_1);
robot.keyPress(KeyEvent.VK_2);
robot.keyPress(KeyEvent.VK_3);
robot.keyPress(KeyEvent.VK_4);
robot.keyPress(KeyEvent.VK_5);
robot.keyPress(KeyEvent.VK_6);
}
}
Uncomment out the setDocumentFilter() line and rerun the code using 0 as the parameter and it works fine.
# 8
Camick
First, Thank you very much for your test program; we even did know how to use Robot.
We learned! And using setdoumentFilter, it works all the time! Great stuff.
Second thing is, The test a) java OverflowDocumentFilter 0 // all text is in the first text field
Works fine 99% on my PC even with out using the SetDocumentFilter.
My CPU is: 1800Mhz But it does not work ALLWAYS on my colleague抯 PC, which has got 3.20GHz. It seems On Fast CPU it does not but slower PC it works. Looks like it does not depend on JRE but it definitely depend on CPU
b) and c) options make improve.
So, make the Scanner抯 slow down rate could help.
We will try that first and then the write the document filter.
Thanks lot. 10 dukes are yours.
Cheers
K