Reading alt JTextArea code

I have a barcode that says: "SerialNumber ALT 0 9 ProductNumber" where ALT 0 9 = Tab .

I read the number in JTextArea , if I write the number manually using the tab key on my keyboard, I get valid input, then I can text.trim().split("\t"); to get the correct entry to get the appropriate serial number and product number. But when reading the barcode that sends ALT 0 9 , it does not read anything.

How do I get JTextArea to accept ALT 0 9 as Tab (or as an alternative split in location).

+6
source share
1 answer

JTextArea does not get Tab at all. Tab switches to the entire GUI to move to the next editable field. Of course, you can bend this rule, intercept Tab in the parent container and force it to send it to the child JTextArea, and then you can even write down your won method for the KeyPressed event and insert the Tab character into the text, but this is a good approach as it changes the user experience . The user expects Tab to go to the next field, but for this particular text area, are you saying that this should be a separator for your text? Another reason - Tab is similar for Space - so in the user interface it is not clear whether it is correct or not.

To avoid all these problems, why not take a simple approach:

 SerialNumber=ProductNumber 

This is clear, understandable, predictable, understandable, and most of all - does not require your question;)

0
source

Source: https://habr.com/ru/post/986809/


All Articles