The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
import-bot (20211) [Avatar] Offline
#1
[Originally posted by harv]

I've got a JTable with a TableModelListener added to it. It's picking up
events fine (for the most part), except when the last event occurs. As long
as I switch between different cells of the JTable, it detects all changes
made, however, there is one scenario it is not detecting the change at. When
the user edits a cell, and immediately clicks on the "OK" button, the change
is not registered with the JTable. I cannot count on the user not just
clicking the "OK" button, which dismisses the dialog, and 'supposedly' saves
any changes he/she made to the table.
Thanks in advance!
import-bot (20211) [Avatar] Offline
#2
Re: Not picking up all events using TableModelListener
[Originally posted by matt]

- I've never tried this, so the following is just an idea for the
first thing I would try in your situation. -

Try using a custom cell editor component with an attached
FocusListener (or have the editor component implement the FocusListener
interface itself, and add itself as a listener). In the focusLost() method
check whether the OK button has the focus, and if so, do whatever you need
to do to set the data displayed by the recently focused cell, to change to
the data the editor contained at the time of focus loss. So you'll need to
always store the contents of the editor component...

Is this idea/explanation readable?
import-bot (20211) [Avatar] Offline
#3
Re: Not picking up all events using TableModelListener
[Originally posted by matt]

> Yes, I understand what you're saying here. I'm actually "retreating" back to
> a custom cell editor smilie I removed the attempts at using a TableModelListener
> preferring instead the approach of using the custom cell editor. My only
> problem with this approach is what appears to me to be a STEEP learning curve
> in actually using the custom cell editor! Maybe it's just me, but cell
> editing/renderering seems to be a complicated development task (compared with
> other components available in Swing).

Yeah, it takes a little while to get editors and renderers straight.
You might want to look over chapter 18 here:

http://www.spindoczine.com/sbe

What you are trying to accomplish is a real-world problem that other
people definitely will, or already have, faced. If you come up with a
nice solution, it would be great if you could post it here!
import-bot (20211) [Avatar] Offline
#4
Re: Not picking up all events using TableModelListener
[Originally posted by harv]

> - I've never tried this, so the following is just an idea for the
> first thing I would try in your situation. -
>
> Try using a custom cell editor component with an attached
> FocusListener (or have the editor component implement the FocusListener
> interface itself, and add itself as a listener). In the focusLost() method
> check whether the OK button has the focus, and if so, do whatever you need
> to do to set the data displayed by the recently focused cell, to change to
> the data the editor contained at the time of focus loss. So you'll need to
> always store the contents of the editor component...
>
> Is this idea/explanation readable?

Yes, I understand what you're saying here. I'm actually "retreating" back to
a custom cell editor smilie I removed the attempts at using a TableModelListener
preferring instead the approach of using the custom cell editor. My only
problem with this approach is what appears to me to be a STEEP learning curve
in actually using the custom cell editor! Maybe it's just me, but cell
editing/renderering seems to be a complicated development task (compared with
other components available in Swing).

Thanks!