I have a Zebex Z-3100 CCD Scanner, which reads barcodes pretty neatly.
What I'm trying to do is to make a java program that can handle the barcodes it reads, and so far I have managed to do it quite allright.
What I'm struggeling with is to make the java program listen to the barcodes without marking the console / textarea(swing).
When I start the program (swing) - and scan the code, it works, but when I use the keypad (which I have implemeted in swing) and press "Clear", it has touched the button "Clear" last, and the textfield is no longer outputting the barcodes that are read.
I tried to solve this by making a seperat thread which only listens to
"Scanner sc = new Scanner(System.in);",
but when I have clicked the button "Clear" it no longer has neither console nor the textfield marked, and no code is read by the program..
Does anybody know an easy way to make the program allways listen to the scanner?
The scanner seems to work like a keyboard -> numbers+enter (e.g 41231 -> enter)
I'm not sure what part of the code to link, but I'll link code if someone needs/requests it!
Thank you so much!
EDIT When I mark the console/textarea it will read codes again. The only part I'm not sure how to do - is to make it listen to the barcode scanner "24/7"!
You problem is a simple focus issue. When you click the "clear" button, it now has keyboard focus, instead, you want to give focus back to the JTextField
When you click the "clear" button call requestFocusInWindow
on the JTextField
to move keyboard focus back to it