?
Solved

Urgent!!! Detecting changes in a cell in JTable

Posted on 2003-02-23
8
Medium Priority
?
495 Views
Last Modified: 2007-12-19
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
Comment
Question by:neo_aquarian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Expert Comment

by:yongsing
ID: 8006650
How about adding a key listener to each of the JTextFields? Then you'll know when the user keys something in the JTextField.
0
 

Author Comment

by:neo_aquarian
ID: 8006668
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
 

Author Comment

by:neo_aquarian
ID: 8006726
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Accepted Solution

by:
gkasinath earned 400 total points
ID: 8015417
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
 
LVL 1

Expert Comment

by:gkasinath
ID: 8015424
I meant from this "having a listener sure is a bad idea" having too many listeners is a bad idea.
0
 

Expert Comment

by:CleanupPing
ID: 9059123
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9671091
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question