• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable input not correctly input-ted when a button is pressed  RSS feed

 
Chin Loong
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,
i got a problem with my application. in my JTable, when I enter a value in a cell, and later press a button to update it, the value won't be properly input-ted into the corresponding cell unless I press the ENTER key after i finish typing the value!
so now i have to *remember* to press ENTER everytime i want to update anything in the table because if i don't, the value enter just before the "update" button is pressed won't be inside.
how do i deal with this problem? do i unfocus the table when the button is pressed, or what? how did u guys deal with this problem?
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your button's actionperformed code , add the following code as first line:
table.getCellEditor().stopCellEditing();
what this does is makes the table's default cell editor to stop editing & stores the value, now you can call tablemodel.getDataVector() ..etc. & get the required value.
This should solve your problem ,Chin.
 
Chin Loong
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, vinod!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!