What are the purposes of using TextAction from AbstractAction? and how to use it for the following:
Caret
Selection in the JTextComponents
KeyBindings
What are the purposes of using TextAction from AbstractAction? and how to use it for the following:
Caret
Selection in the JTextComponents
KeyBindings
While composing this answer, I recalled a venerable
HTMLDocumentEditor
by Charles Bell that illustrates the typical usage of the subclasses found injavax.swing.text.TextAction
. That editor is listed among the credits ofMetaphase Editor
. This related example showing actions found inStyledEditorKit
follows the same approach. All such actions are suitable for Key Bindings, and all operate on the current selection maintained by theCaret
, whenever possible.From Java Swing 2nd Edition:
Here are some examples that implement TextAction:
Custom Editing Command
Finding Word Boundaries