• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

KeyEvent handling in a JTable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic