• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

KeyEvent handling in a JTable  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy folks!
I'm trying to implement a JTable that automatically adds and deletes rows as the user types. The last row will always be blank (except for data in the 1st column), so when a user types something in any column of the last row, I'd like it to add a new blank row to the bottom of the table. In addition, I'd like rows that become empty from a user pressing backspace or delete to automatically disappear.
What I've written so far almost works, but ocassionally when a new row gets added, the characters that the user typed disappear. Deletion doesn't work predictably either. Here's the class:

Thanks for your help!
Rafe
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
the values typed by the user disappear when editing is cancelled. this is a bug in JTable:
http://developer.java.sun.com/developer/bugParade/bugs/4330950.html
http://developer.java.sun.com/developer/bugParade/bugs/4709394.html
these bugs come up when the cell is still in editing mode, and the table loses focus. but it can happen even when just another cell is selected (through keyboard action). I didn't find the bug ids in the bugparade at once.
it _seems_ as this is fixed in 1.4.1.
-------------------
what concerns the deletion of the row which is not propagated to the view (= JTable). Be sure, your tablemodel fires an event on row deletion.

chantal
 
Rafe Thayer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help Chantal. Finally got it working reasonably. The problem was that I didn't set an appropriate default cell editor. Also, FYI, when the cell editor cancels editing, the data still disappears. In my case, the cell loses focus when a new row is added (which is after the first character gets typed in the nth cell). Does anyone know offhand how to do a fireTableRowsInserted(x,y) without changing the currently selected and editing cell?
Here's what the code looks like now:
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!