————————————————————————————————————————————————————————————————————————
Table of content of the tutorial
Actions are operations user can do with JEditorPane content. There are 2 types of actions - Navigation actions and Editing actions. The navigation actions don’t change content but move caret, select text etc. Editing actions change Document structure which in turn changes views e.g. InsertContentAction or DeleteNextCharAction. Actions available in an EditorKit are defined by list returned from method
public Action[] getActions()
To add a specific action it should be placed it in the list. For example HTMLEditorKit defines some HTML specific actions like InsertTable or InsertOrderedList. All of them are added in a list which is merged with list returned by super EditorKit class. The custom actions are added like this:
public Action[] getActions() {
return TextAction.augmentList(super.getActions(), this.defaultActions);
}
where defaultAction is an array of kit actions.
Also it’s possible to add some listener or component specific code via overriding methods.
public void install(JEditorPane c)
public void deinstall(JEditorPane c)
When a kit is set to a JEditorPane the pane is passed to the method. If we look in HTMLEditorKit source we can see that the kit added MouseListener and MouseMotionListener – linkHandler to process links. The same way any other custom listeners/actions can be added.
The next step is EditorKit creation example
Back to Table of Content
傲轩游戏网