The JTable is in a JFrame. Also in that JFrame are a couple of buttons
that, when pressed, cause saving of the data. The first thing I do in
the ActionListener for the button is call JTable.editingStopped(null).
The result is that whatever cell was being edited gets set to zero...:-(
Stepping into the code, I find that editingStopped() call properly calls
my TableModel setValueAt() method as expected. However, though the row
and column are right, the value Object is null? My code sees the null
and changes the cell value to zero. (I can obviously fix it so that null
no longer has that side effect, but it still ain't right)
Breaking on the setValueAt(), I find that it is called properly when I
tab out of an edited cell, or if I click in a new cell after editing.
That is, in those cases, setValueAt() is called with the proper value
Object, and everything acts as expected.
As a test, I put some code before the editingStopped(), to grab the
editor and get the editor text from that. I find that I do get the
right editor, but that the editor then tells me that the edited text is
null? That is, doing this check gives me the same results that are
otherwise sent to setValueAt() by the next editingStopped() call.
So maybe this isn't allowed in an ActionListener for some reason??
I'm really confused here... :-(
Oh yes, two other info points. First, I am using the default editor for
JTable here. Also, I tried adding a KeyListener to the table to see
what the editor was then, but the listeners were never called during
typing?
As always, all help is appreciated! :-)
--
- Burt Johnson
MindStorm Productions, Inc.
http://www.mindstorm-inc.com
> The JTable is in a JFrame. Also in that JFrame are a couple of buttons
> that, when pressed, cause saving of the data. The first thing I do in
> the ActionListener for the button is call JTable.editingStopped(null).
> The result is that whatever cell was being edited gets set to zero...:-(
Try doing the following instead:
if (table.isEditing())
table.getCellEditor().stopCellEditing();
--
lar3ry gensch lar...@mediaone.net
"May I have ten thousand marbles, please?"
> In article <1enrkjn.13903g11yjt1xmN%bu...@mindstorm-inc.com>,
> bu...@mindstorm-inc.com (Burt Johnson) writes:
>
> > The JTable is in a JFrame. Also in that JFrame are a couple of buttons
> > that, when pressed, cause saving of the data. The first thing I do in
> > the ActionListener for the button is call JTable.editingStopped(null).
> > The result is that whatever cell was being edited gets set to zero...:-(
>
> Try doing the following instead:
>
> if (table.isEditing())
> table.getCellEditor().stopCellEditing();
Bingo! That solved the problem completely! Thanks!
I guess I should go through the other 67 calls to editingStopped() and
see if they should change to that approach too.
Any idea why editingStopped doesn't work right, yet stopCellEditing
does?