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);
 

See Also:
  • Field Details

  • 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

    • init

      private void init()
    • getCaretListener

      CaretListener getCaretListener()
    • getUndoableEditListener

      UndoableEditListener getUndoableEditListener()
    • 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.
    • updateActionState

      private void updateActionState()
      Updates the state of the actions in response to an undo/redo operation.

    • getParagraphSelector

      public JComboBox 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

    • applyTag

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

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

      private void find()
    • 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 -
    • hasCommand

      public boolean hasCommand(Object command)
      Description copied from interface: Targetable
      Return a flag that indicates if a command is supported.
      Specified by:
      hasCommand in interface Targetable
      Parameters:
      command - is a Action.ACTION_COMMAND_KEY
      Returns:
      true if command is supported; false otherwise
    • getCommands

      public Object[] getCommands()
      Description copied from interface: Targetable
      Returns an array of supported commands. If this Targetable doesn't support any commands (which is unlikely) then an empty array is returned.
      Specified by:
      getCommands in interface Targetable
      Returns:
      array of supported commands
    • doCommand

      public boolean doCommand(Object command, Object value)
      Description copied from interface: Targetable
      Perform the command using the object value.
      Specified by:
      doCommand in interface Targetable
      Parameters:
      command - is a Action.ACTION_COMMAND_KEY
      value - an arbitrary value. Usually this will be EventObject which trigered the command.
    • getScrollableUnitIncrement

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