aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes another table problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "another table problem" Watch "another table problem" New topic
Author

another table problem

Sayuri Coppinger
Greenhorn

Joined: Jun 06, 2001
Posts: 20
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

Joined: Jul 17, 2001
Posts: 22
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

Joined: May 02, 2001
Posts: 57
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
Sayuri Coppinger
Greenhorn

Joined: Jun 06, 2001
Posts: 20
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

Joined: May 02, 2001
Posts: 57
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

Joined: Jun 06, 2001
Posts: 20
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

Joined: Jun 06, 2001
Posts: 20
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: another table problem