The particular thing I'm interested in at the moment is JTable's 'cancel' Action ... in particular I'm trying to find out why, with an InputVerifier set for the JTable's CellEditor's Component (JTextField), the IV's shouldYieldFocus() method is called not once, but twice (!) when I press Escape.
I have checked that it is the JTable's ActionMap entry for VK_CANCEL ('cancel') which is being run here.
Furthermore I find that the JTable's editingCanceled method is NOT called when I press Escape like this... and this in turn makes is slightly difficult currently to let the IV know that a cancellation action is happening (and that verify should not therefore be called).
Of course it's easy enough to create my own "Cancel" Action, which calls the cancel Action obtained from the JTable's ActionMap, but also sets a flag saying "disregard the text of the JTF... we're cancelling". But I'd just like to see what the cancellation Action actually consist of... i.e. the code.
later
Having had a look at the source code for one or two classes, in particular JComponent and AbstractCellEditor, it appears that the IV's shouldYieldFocus is triggered, perhaps not that surprisingly, when a request to take focus away is made.
I haven't yet solved my specific problem, and I'd still like to know if it's possible to find the code of these ActionMap Actions...
Yes. As discussed here, and illustrated here, subclasses of
TextAction
are installed as key bindings by the text component's UI delegate, typically a subclass ofBasicTextUI
. EachAction
is typically an instance of a class nested in the relevant editor kit. For example,DefaultEditorKit
includes severalpublic
actions, as well as a larger number of package-private actions used internally.The handler for the
Action
named"cancel"
may be found, among others, in theJTable
UI delegate, typically a subclass ofBasicTableUI
.As noted in Validating Input, ensure that your implementation of
verify()
has no side effects. A complete example is examined here. Examples using anInputVerifier
in aTableCellEditor
are seen here and here.Actions and keys bound
WHEN_FOCUSED
toJTextField
bycom.apple.laf.AquaLookAndFeel
: