Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in Listening to Key events in JTable  RSS feed

 
Manju Krishna
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a Jtable in my Single Frame Work Appln. I have editable and uneditable fields in that. Whenever the user changes data in an editable cell, and tries to move away from that panel before saving, We prompt the user to save the changes or not.

The problem is, when the user had double clicked on the editable cell, but did not change/ key in any data..
Stil the trigger for Save changes gets called..

How can i do a KeyListener here? Or any other way to identify if the current cell data has changed or not??

Please help...
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a TableModelListener instead. That will be notified when the TableModel actually changes.

Alternatively, you can re-implement the setValueAt method of your TableModel. Kind of like this:
 
Manju Krishna
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This didnt work for me..

I have set my table to blink with cursor on single click for editable columns using the DefaultCellEditor's
setClickCountToStart ..

When i key in any data the code doesnt reach this setValueAt overrided method..
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because the data is not committed yet. If the user presses escape the changes are ignored. Only when you commit (usually by pressing enter) this method is called, and the model really contains that data. You can use the following code to commit all changes when your table looses focus:
 
Manju Krishna
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this check can be implemented only if the table looses focus??
like moving from one cell to another.. ?

I need to capture that the cell is edited as it is typed in and enable the save button only on user keying in any data..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!