Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

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?

0
neo_aquarian
Asked:
neo_aquarian
1 Solution
 
yongsingCommented:
How about adding a key listener to each of the JTextFields? Then you'll know when the user keys something in the JTextField.
0
 
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?
0
 
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?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
gkasinathCommented:
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..

Regds
Gautham Kasinath
0
 
gkasinathCommented:
I meant from this "having a listener sure is a bad idea" having too many listeners is a bad idea.
0
 
CleanupPingCommented:
neo_aquarian:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
jimmackCommented:
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now