Vetoing a change by DefaultCellEditor in JTable

B

Brian J. Sayatovic

I'm using a DefaultCellEditor with a JTextField to capture a String
that is ultimately passed to setValueAt in my TableModel. In that
method, I have logic which could throw an exception if the String's
contents proves to be invalid (i.e. one use is where the String is a
regular expression that might be syntactically invalid).

How can I handle this? Right now, the code throws an Exception which
I'd like to catch, display a dialog, and then return the user to
editing without ever committing the value. Is this easily doable?

Regards,
Brian.
 
T

Tor Iver Wilhelmsen

How can I handle this? Right now, the code throws an Exception which
I'd like to catch, display a dialog, and then return the user to
editing without ever committing the value. Is this easily doable?

Override the TableModel's stopCellEditing() to catch the exception and
return false, otherwise return true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top