Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another table problem

 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I make changes to a cell, I can see that the value has changed in the table, but I can't retrieve the value until the selection (not focus)is no longer at that cell, but at another cell. I can change the focus to a different component, but as
long as the cell selection remains, the value does not get set in my underlying data object.
I've tried clearing the cell selection, setting the setCellSelection back to false, firing a table model event with the cell that gets updated, implementing the list selection listener and nothing seems to be working
Does anybody know why I have to select another cell before the value gets set, and how I can get around this?
Any ideas would be very much appreciated!
Thanks,
Sayuri
 
Nathanael Ulrick
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that JTable only updates its TableModel when editing is finished, as specified in CellEditorListener.
I imagine what you would need to do is to add your own listener to the Component retrieved from getEditorComponent() whenever a new cell is being edited.
 
Swamy Vatti
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you are doing some action, lets say button click, after updating the table, put this code in the action performed method.
int row = yourTable.getEditingRow();
int col = yourTable.getEditingColumn();
if (row != -1 && col != -1)
yourTable.getCellEditor(row,col).stopCellEditing();
I guess this should work perfect.
 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for replying. I added the code below, but it didn't work. The values only get set if I select another cell. I am running out of ideas....
Originally posted by Swamy Vatti:
Hi,
If you are doing some action, lets say button click, after updating the table, put this code in the action performed method.
int row = yourTable.getEditingRow();
int col = yourTable.getEditingColumn();
if (row != -1 && col != -1)
yourTable.getCellEditor(row,col).stopCellEditing();
I guess this should work perfect.

 
Swamy Vatti
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can you give me some more info, the sequence of events...
Like after editing the cell, what do you do?
I had the same problem and now its working perfect.
Can you tell me what JDK version are you using?
 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
After I make a change to the cell, I simply click on a button. I've added the code you wrote above to my action performed and it still doesn't update the model. I am using jdk 1.3
Also, I have another question for you. Some of my cells are readonly, and when I tab through the cells, I want to skip the readonly cells. I was thinking I could check if the cells is editable and just get the next focusable (or editable cell). Is there a quick way of doing this, or do I have to implement the key listener and look for the tab and shift tab keys?
Thanks for your help and interest !
Originally posted by Swamy Vatti:
Hi,
Can you give me some more info, the sequence of events...
Like after editing the cell, what do you do?
I had the same problem and now its working perfect.
Can you tell me what JDK version are you using?

 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wanted to update anyone having the same problems I mentioned above, that what I had forgotten to do was to call fireTableCellUpdated method when setting the value.
As for the tabbing issue, I had to use a combination of focus listener, key listener and focus manager to get the focus to go to only editable cells and if the user was on the last cell to go to next focusable component. It sounds simple, but it was a struggle to get it right since my editable cell could be anywhere within the table.
Thanks to all who participated in this thread
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic