Class JXEditorPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, Targetable

@JavaBean public class JXEditorPane extends JEditorPane implements Targetable

JXEditorPane offers enhanced functionality over the standard JEditorPane. Unlike its parent, JXEdtiorPane honors display properties by default. Users can revert to the behavior of JEditorPane by setting the property to false.

Additional Features

Improved text editing
The standard text component commands for cut, copy, and paste used enhanced selection methods. The commands will only be active if there is text to cut or copy selected or valid text in the clipboard to paste.
Improved HTML editing
Using the context-sensitive approach for the standard text commands, JXEditorPane provides HTML editing commands that alter functionality depending on the document state. Currently, the user can quick-format the document with headers (H# tags), paragraphs, and breaks.
Built-in UndoManager
Text components provide UndoableEditEvents. JXEditorPane places those events in an UndoManager and provides undo/redo commands. Undo and redo are context-sensitive (like the text commands) and will only be active if it is possible to perform the command.
Built-in search
Using SwingX search mechanisms, JXEditorPane provides search capabilities, allowing the user to find text within the document.

Example

Creating a JXEditorPane is no different than creating a JEditorPane. However, the following example demonstrates the best way to access the improved command functionality.

 JXEditorPane editorPane = new JXEditorPane("some URL");
 add(editorPane);
 JToolBar toolBar = ActionContainerFactory.createToolBar(editorPane.getCommands[]);
 toolBar.addSeparator();
 toolBar.add(editorPane.getParagraphSelector());
 setToolBar(toolBar);
 
Author:
Mark Davidson
See Also:
  • Constructor Details

    • JXEditorPane

      public JXEditorPane()
      Creates a new JXEditorPane. The document model is set to null.
    • JXEditorPane

      public JXEditorPane(String url) throws IOException
      Creates a JXEditorPane based on a string containing a URL specification.
      Parameters:
      url - the URL
      Throws:
      IOException - if the URL is null or cannot be accessed
    • JXEditorPane

      public JXEditorPane(String type, String text)
      Creates a JXEditorPane that has been initialized to the given text. This is a convenience constructor that calls the setContentType and setText methods.
      Parameters:
      type - mime type of the given text
      text - the text to initialize with; may be null
      Throws:
      NullPointerException - if the type parameter is null
    • JXEditorPane

      public JXEditorPane(URL initialPage) throws IOException
      Creates a JXEditorPane based on a specified URL for input.
      Parameters:
      initialPage - the URL
      Throws:
      IOException - if the URL is null or cannot be accessed
  • Method Details

    • setEditorKit

      public void setEditorKit(EditorKit kit)
      Overidden to perform document initialization based on type.
      Overrides:
      setEditorKit in class JEditorPane
    • initActions

      protected void initActions()
      Register the actions that this class can handle.
    • getParagraphSelector

      public JComboBox<HTML.Tag> getParagraphSelector()
      Retrieves a component which will be used as the paragraph selector. This can be placed in the toolbar.

      Note: This is only valid for the HTMLEditorKit

      Returns:
      JComboBox
    • applyTag

      protected void applyTag(HTML.Tag tag)
      Applys the tag to the current selection
      Parameters:
      tag - HTML Tag
    • paste

      public void paste()
      The paste method has been overloaded to strip off the html body tags This doesn't really work.
      Overrides:
      paste in class JTextComponent
    • getSearchable

      public Searchable getSearchable()
      Returns:
      a not-null Searchable for this editor.
    • setSearchable

      public void setSearchable(Searchable searchable)
      sets the Searchable for this editor. If null, a default searchable will be used.
      Parameters:
      searchable - Searchable
    • hasCommand

      public boolean hasCommand(Object command)
      Specified by:
      hasCommand in interface Targetable
    • getCommands

      public Object[] getCommands()
      Specified by:
      getCommands in interface Targetable
    • doCommand

      public boolean doCommand(Object command, Object value)
      Specified by:
      doCommand in interface Targetable
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
      Specified by:
      getScrollableUnitIncrement in interface Scrollable
      Overrides:
      getScrollableUnitIncrement in class JTextComponent