Java Utililty Methods JTextComponent Action

List of utility methods to do JTextComponent Action

Description

The list of methods to do JTextComponent Action are organized into topic(s).

Method

ActiongetAction(JTextComponent component, String actionName)
Search the given text component's list of actions for an action with the given name.
for (Action a : component.getActions()) {
    if (actionName.equals(a.getValue(Action.NAME))) {
        return a;
return null;
TgetAction(JTextComponent target, Class aClass)
Searches all actions of a JTextComponent for ab action of the given class and returns the first one that matches that class, or null if no Action is found
for (Object k : target.getActionMap().allKeys()) {
    Action a = target.getActionMap().get(k);
    if (aClass.isInstance(a)) {
        @SuppressWarnings("unchecked")
        T t = (T) a;
        return t;
return null;
voidsetHistoryActions(JTextComponent textComponent)
set History Actions
Document doc = textComponent.getDocument();
UndoManager undo = new UndoManager();
doc.addUndoableEditListener(new UndoableEditListener() {
    @Override
    public void undoableEditHappened(UndoableEditEvent evt) {
        undo.addEdit(evt.getEdit());
});
...