• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

TableCellEditor - edit value of last cell before table focus lost

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

I have looked on these forums and on the net for the answer to this question. The problem seems quite common, but I can't find the solution.

On my JTable I have a TableCellEditor. It is working for every cell except the final cell that gets edited before the table loses focus. For example, if I edit a cell and then click a button, that specific edit does not get saved.

Where does this get processed so that I can catch it?

Many kind regards,
Rachel
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your class should implement TableModelListener and include a tableChanged method.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

Thanks for the suggestion, but that doesn't fix the problem.

Cheers,
Rachel
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your tableChanged method will be called every time a cell in your table is modified.

Including the last one.

If, inside of this method, you can see the new value for that cell, then the problem must be elsewhere.

Can you provide any code?
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If, inside of this method, you can see the new value for that cell, then the problem must be elsewhere



I can't see the value inside that method.


OK. Don't let the class names fool you, it's for a translation software for our website.

code for the table model


code for the cell editor


[ November 01, 2004: Message edited by: Rachel Swailes ]
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you issue this statement:



I'm assuming that you are only interested in this one element, right?

ok, given that, what is the output you see from this statement? Is it the
"old value" (the value held in the table before you edited it) or a null value or perhaps something else?
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wanted to print out this row because this is the info I need to get a handle to in order to save it.
I changed the code for the tableChanged to look like this...



So here is the output for the following scenarios:

1 - Write in a cell and tab to another cell

Row Information: Hello

2 - Write in a cell and click somewhere else on the program (in this case, the list that generates a new table

Null Pointer exception

3 - Write in a cell and then click the close button (calls System.exit(0));

Row Information: Hello


4 - Write in a cell and then click the x button to close.

Null Pointer exception
[ November 02, 2004: Message edited by: Rachel Swailes ]
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say "write in a cell" I'm assuming that you mean column 1 and not column 0 (since that is what you are printing).

I can't say I'm entirely clear why you are using this call in your code:


If you have built this table from the contents of your "rows" object, then I might suggest that you use fireTableDataChanged() in your setData() method.

Also, check to make sure that this statement:


isn't returning a null under some condition.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there.

I just wanted to say thanks for the help you are giving to help me get this right. I very much appreciate it!

I changed the code to use the fireTableDataChanged and not I don't have to catch that null pointer exception in the tableChanged anymore. So that's cool.

Yes, only column[1] is editable.

The getDestinationKeyPair doesn't return a null at any time.

So after those additions these are the results in the four scenarios...
1 - Edit cell and click to another cell - Works
2 - Edit cell and click close (calling system.exit) - Works
3 - Edit cell and click x button - Doesn't work but I've decided that that's right so we'll forget this one.

So the last scenario to get working is the following.
On my app, there is a list. When clicking on the list, the table is changed to show the information that is detailed by the item that is selected in the list.
What is happening now is that when the user edits a cell and then clicks on the item in the list, I then get an ArrayOutOfBounds Exception in the setValue of the table model. I have a feeling that this is because the data in the table is changing at that moment so I'm going to try and get the click on the list to first save the changes and then show the new table data.

Do you think my suspicions sound right?

Cheers, and many many thanks again!
Rachel
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it did work. I told the TableCellEditor to stopEditing whenever I click on the list. It's not the best way to do it I'm sure, but it works!

Thanks for putting up with me being slow about this.

Cheers,
Rachel
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps it's better to adde a focuslistener to the celleditor and in the focusLost method add a call to the stopCellEditing of the editor..

That way you can select other components then just your list..
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'll keep that in mind!
 
reply
    Bookmark Topic Watch Topic
  • New Topic