Is there a version of postActionEvent for KeyEvent (specifically for a JTextArea)?

Posted by Brian Pelc on Stack Overflow See other posts from Stack Overflow or by Brian Pelc
Published on 2012-10-26T18:00:13Z Indexed on 2012/10/26 23:01 UTC
Read the original article Hit count: 230

Filed under:
|
|
|
|

I'm writing a program that contains multiple JTextFields and 2 JTextAreas within an input panel. I have a submit button on the bottom. I have it set up so when a user types something into each field (including the JTextAreas) and hits the Enter key, it updates a text file, and when they press the submit button it updates the file then outputs a new version of it in the local directory.

If the user presses Enter in any of the fields, it validates their input, however, I want to re-validate all fields when they press the submit button. Each field (again, JTextAreas included) has it's own validation check within its ActionListener or KeyListener (for the JTextAreas). It's easy enough to use postActionEvent() for the JTextFields, but is there a similar method for the JTextAreas to force fire a KeyEvent? I don't want to duplicate code and consume memory by re-writing the validation for those 2 Components inside the ActionEvent for the JButton.

Unfortunately, I can't provide a sample because I'm writing the program on a classified machine (PC).

© Stack Overflow or respective owner

Related posts about java

Related posts about swing