Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem in Listening to Key events in JTable

 
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic