# Class RichTextArea

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.ui.AbstractEditorComponent
com.codename1.ui.RichTextArea

All Implemented Interfaces:
  `Animation, Editable, StyleListener, Iterable<Component>`

public class RichTextArea extends AbstractEditorComponent

A native visual editor for rich text / HTML content (a WYSIWYG editor).

`RichTextArea` lets the user visually edit formatted text - bold, italic, lists, links, colors, headings and more - and exchange the result as HTML with your application. It works on phones and tablets (with the on screen virtual keyboard) as well as on desktops (with a physical keyboard).

By default the editor is implemented as a `contenteditable` surface hosted inside the platform's native web widget (`BrowserComponent`), which makes it 100% cross platform and gives correct keyboard, selection and IME behavior on every device for free. A platform port may transparently replace this with a fully native editing widget; see `com.codename1.impl.CodenameOneImplementation#createNativeEditorPeer(Object, String)`.

##### Basic usage

    Form hi = new Form("Rich Text", new BorderLayout());
    RichTextArea editor = new RichTextArea();
    editor.setHtml("<p>Hello <b>world</b></p>");

    Toolbar tb = hi.getToolbar();
    tb.addCommandToRightBar("B", null, e -> editor.bold());
    tb.addCommandToRightBar("I", null, e -> editor.italic());

    hi.add(BorderLayout.CENTER, editor);
    hi.show();

    // later, read the edited content back:
    editor.getHtml(html -> Log.p("User wrote: " + html));

- ## Field Summary

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RichTextArea()`
  Creates an empty rich text editor.
  `RichTextArea(String html)`
  Creates a rich text editor initialized with the supplied HTML.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `bold()`
  Toggles bold styling on the current selection.
  `void`
  `createLink(String url)`
  Wraps the current selection in a hyperlink.
  `void`
  `getHtml(SuccessCallback<String> callback)`
  Retrieves the current editor content as an HTML string.
  `String`
  `getPlaceholder()`
  Returns the current placeholder text.
  `void`
  `getText(SuccessCallback<String> callback)`
  Retrieves the current editor content as plain text (markup stripped).
  `void`
  `indent()`
  Increases the indentation of the current block.
  `void`
  `insertHtml(String html)`
  Inserts the supplied HTML fragment at the current cursor position.
  `void`
  `insertImage(String url)`
  Inserts an image at the current cursor position.
  `void`
  `insertOrderedList()`
  Converts the current block(s) into an ordered (numbered) list.
  `void`
  `insertUnorderedList()`
  Converts the current block(s) into an unordered (bulleted) list.
  `void`
  `italic()`
  Toggles italic styling on the current selection.
  `void`
  `justifyCenter()`
  Center aligns the current block.
  `void`
  `justifyLeft()`
  Left aligns the current block.
  `void`
  `justifyRight()`
  Right aligns the current block.
  `void`
  `outdent()`
  Decreases the indentation of the current block.
  `void`
  `queryCommandState(String command, SuccessCallback<Boolean> callback)`
  Queries whether a given inline command (e.g. `"bold"`, `"italic"`, `"underline"`) is currently active for the selection, which is useful to keep a formatting toolbar in sync.
  `void`
  `redo()`
  Redoes the last undone editing operation.
  `void`
  `removeFormat()`
  Removes all inline formatting from the current selection.
  `void`
  `removeLink()`
  Removes the hyperlink covering the current selection.
  `void`
  `setBlockFormat(String tag)`
  Applies a block format / heading to the current block.
  `void`
  `setFontSize(int size)`
  Applies a relative font size (1 through 7, matching the legacy HTML font size scale) to the current selection.
  `void`
  `setForegroundColor(int rgb)`
  Sets the foreground (text) color of the current selection.
  `void`
  `setHighlightColor(int rgb)`
  Sets the highlight (background) color of the current selection.
  `void`
  `setHtml(String html)`
  Replaces the entire editor content with the supplied HTML.
  `void`
  `setPlaceholder(String text)`
  Sets the placeholder text shown when the editor is empty.
  `void`
  `strikeThrough()`
  Toggles strike-through styling on the current selection.
  `void`
  `underline()`
  Toggles underline styling on the current selection.
  `void`
  `undo()`
  Undoes the last editing operation.

  ### Methods inherited from class AbstractEditorComponent

  `addChangeListener, addReadyListener, blurEditor, command, fireEditorEvent, focusEditor, getInternalBrowser, isEditable, isEditorReady, isNativeEditor, onReady, query, removeChangeListener, removeReadyListener, setEditable`

  ### Methods inherited from class Container

  `add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices`

  ### Methods inherited from class Component

  `addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Iterable

  `forEach`

- ## Constructor Details

  - ### RichTextArea

    public RichTextArea()
    Creates an empty rich text editor.

  - ### RichTextArea

    public RichTextArea(String html)

    Creates a rich text editor initialized with the supplied HTML.

    ###### Parameters

    - `html`: the initial HTML content

- ## Method Details

  - ### setHtml

    public void setHtml(String html)

    Replaces the entire editor content with the supplied HTML.

    ###### Parameters

    - `html`: the HTML to display and edit

  - ### getHtml

    public void getHtml(SuccessCallback<String> callback)

    Retrieves the current editor content as an HTML string. The callback is invoked on the EDT.

    ###### Parameters

    - `callback`: receives the HTML content

  - ### getText

    public void getText(SuccessCallback<String> callback)

    Retrieves the current editor content as plain text (markup stripped). The callback is invoked on the EDT.

    ###### Parameters

    - `callback`: receives the plain text content

  - ### insertHtml

    public void insertHtml(String html)

    Inserts the supplied HTML fragment at the current cursor position.

    ###### Parameters

    - `html`: the HTML fragment to insert

  - ### insertImage

    public void insertImage(String url)

    Inserts an image at the current cursor position.

    ###### Parameters

    - `url`: the image URL (may be an http(s) URL or a data: URI)

  - ### setPlaceholder

    public void setPlaceholder(String text)

    Sets the placeholder text shown when the editor is empty.

    ###### Parameters

    - `text`: the placeholder hint

  - ### getPlaceholder

    public String getPlaceholder()
    Returns the current placeholder text.

  - ### bold

    public void bold()
    Toggles bold styling on the current selection.

  - ### italic

    public void italic()
    Toggles italic styling on the current selection.

  - ### underline

    public void underline()
    Toggles underline styling on the current selection.

  - ### strikeThrough

    public void strikeThrough()
    Toggles strike-through styling on the current selection.

  - ### insertOrderedList

    public void insertOrderedList()
    Converts the current block(s) into an ordered (numbered) list.

  - ### insertUnorderedList

    public void insertUnorderedList()
    Converts the current block(s) into an unordered (bulleted) list.

  - ### indent

    public void indent()
    Increases the indentation of the current block.

  - ### outdent

    public void outdent()
    Decreases the indentation of the current block.

  - ### justifyLeft

    public void justifyLeft()
    Left aligns the current block.

  - ### justifyCenter

    public void justifyCenter()
    Center aligns the current block.

  - ### justifyRight

    public void justifyRight()
    Right aligns the current block.

  - ### createLink

    public void createLink(String url)

    Wraps the current selection in a hyperlink.

    ###### Parameters

    - `url`: the link target

  - ### removeLink

    public void removeLink()
    Removes the hyperlink covering the current selection.

  - ### setForegroundColor

    public void setForegroundColor(int rgb)

    Sets the foreground (text) color of the current selection.

    ###### Parameters

    - `rgb`: the color as a 0xRRGGBB integer

  - ### setHighlightColor

    public void setHighlightColor(int rgb)

    Sets the highlight (background) color of the current selection.

    ###### Parameters

    - `rgb`: the color as a 0xRRGGBB integer

  - ### setBlockFormat

    public void setBlockFormat(String tag)

    Applies a block format / heading to the current block. Common values are `"p"`, `"h1"` .. `"h6"`, `"pre"` and `"blockquote"`.

    ###### Parameters

    - `tag`: the block tag name

  - ### setFontSize

    public void setFontSize(int size)

    Applies a relative font size (1 through 7, matching the legacy HTML font size scale) to the current selection.

    ###### Parameters

    - `size`: a value between 1 and 7

  - ### removeFormat

    public void removeFormat()
    Removes all inline formatting from the current selection.

  - ### undo

    public void undo()
    Undoes the last editing operation.

  - ### redo

    public void redo()
    Redoes the last undone editing operation.

  - ### queryCommandState

    public void queryCommandState(String command, SuccessCallback<Boolean> callback)

    Queries whether a given inline command (e.g. `"bold"`, `"italic"`, `"underline"`) is currently active for the selection, which is useful to keep a formatting toolbar in sync. The callback is invoked on the EDT.

    ###### Parameters

    - `command`: the command name to test

    - `callback`: receives true if the command is active for the current selection