问题
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...
回答1:
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 of BasicTextUI. Each Action
is typically an instance of a class nested in the relevant editor kit. For example, DefaultEditorKit includes several public
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 the JTable
UI delegate, typically a subclass of BasicTableUI.
As noted in Validating Input, ensure that your implementation of verify()
has no side effects. A complete example is examined here. Examples using an InputVerifier
in a TableCellEditor
are seen here and here.
Actions and keys bound WHEN_FOCUSED
to JTextField
by com.apple.laf.AquaLookAndFeel
:
beep:
caret-backward: LEFT, KP_LEFT, ctrl B
caret-begin: ctrl P, meta UP, meta KP_UP, HOME
caret-begin-line: KP_UP, ctrl A, UP, meta KP_LEFT, meta LEFT
caret-begin-paragraph:
caret-begin-word:
caret-down:
caret-end: ctrl N, END, meta KP_DOWN, ctrl V, meta DOWN
caret-end-line: DOWN, meta KP_RIGHT, ctrl E, meta RIGHT, KP_DOWN
caret-end-paragraph:
caret-end-word:
caret-forward: RIGHT, ctrl F, KP_RIGHT
caret-next-word: alt KP_RIGHT, alt RIGHT
caret-previous-word: alt KP_LEFT, alt LEFT
caret-up:
copy:
copy-to-clipboard: meta C, COPY
cut:
cut-to-clipboard: CUT, meta X
default-typed:
delete-next: DELETE, ctrl D
delete-next-word: alt DELETE
delete-previous: BACK_SPACE, ctrl H
delete-previous-word: alt BACK_SPACE, ctrl W
dump-model:
insert-break:
insert-content:
insert-tab:
notify-field-accept: ENTER
page-down:
page-up:
paste:
paste-from-clipboard: meta V, PASTE
requestFocus:
select-all: meta A
select-line:
select-paragraph:
select-word:
selection-backward: shift LEFT, shift KP_LEFT
selection-begin: shift meta KP_UP, shift meta UP, shift HOME
selection-begin-line: shift UP, shift meta KP_LEFT, shift KP_UP, shift meta LEFT
selection-begin-paragraph:
selection-begin-word:
selection-down:
selection-end: shift meta DOWN, shift meta KP_DOWN, shift END
selection-end-line: shift meta KP_RIGHT, shift DOWN, shift KP_DOWN, shift meta RIGHT
selection-end-paragraph:
selection-end-word:
selection-forward: shift KP_RIGHT, shift RIGHT
selection-next-word: shift alt KP_RIGHT, shift alt RIGHT
selection-page-down: shift PAGE_DOWN
selection-page-left: shift meta PAGE_UP
selection-page-right: shift meta PAGE_DOWN
selection-page-up: shift PAGE_UP
selection-previous-word: shift alt LEFT, shift alt KP_LEFT
selection-up:
set-read-only:
set-writable:
toggle-componentOrientation: shift ctrl O
unselect: meta BACK_SLASH
来源:https://stackoverflow.com/questions/31659063/is-there-anywhere-we-can-find-the-actual-code-of-the-actions-in-framework-suppli