Urgent!!! Detecting changes in a cell in JTable

Hello folks,
I got this problem that i have to solve urgently- i have a JTable which uses the DefaultTableModel and has a listener extending TableModelListener. I have three columns which are all JtextFields. What i want is for the listener to be notified whenever the data in one of the cells changes- as the user id typing in the cell- I want to do some validation and change the color of the text. Right now the listener is notified only when the focus changes from the cell. Is there any way of the listener being notified while the cell is having focus and its contents change?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How about adding a key listener to each of the JTextFields? Then you'll know when the user keys something in the JTextField.
neo_aquarianAuthor Commented:
I forgot to add that the rows can be added or removed by the user. Do you mean to say that I should add a key listener to each of the components in the table? Isnt that inefficient?
neo_aquarianAuthor Commented:
I forgot to add that the rows can be added or removed by the user. Do you mean to say that I should add a key listener to each of the components in the table? Isnt that inefficient?
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Well, having a listener sure is a bad idea..
but stretching the Observer pattern a lil more..
what you CAN do is have a Generic Cell listener, which can identify on some parameters what cell has changed and how.
What you will need to do is have each cell implement a known CellInterface.
The CellInterface will have the usual methods for the cell and also a custom method, fireCellChanged()

With a binding to a listener, when the fireCellChanged is triggered, it notifies the listener, which finds out what object has changed. Further, if you can store the state of each cell, then the listener, can also notify as to how the cell has changed.

In the above mentioned scenario, you will be using only one instance/thread, of Listener, doing the listening.

I hope it helps.. if you need more inputs, fell free..

Gautham Kasinath

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I meant from this "having a listener sure is a bad idea" having too many listeners is a bad idea.
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept gkasinath's comment as answer

Please leave any comments here within the next seven days.


EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.