Class CodeArea
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
jfx.incubator.scene.control.richtext.RichTextArea
jfx.incubator.scene.control.richtext.CodeArea
- All Implemented Interfaces:
Styleable
,EventTarget
,Skinnable
CodeArea is an editable text component which supports styling (for example, syntax highlighting) of plain text.
Unlike its base class RichTextArea
, the CodeArea
requires a special kind of model to be used,
a CodeTextModel
.
Creating a CodeArea
The following example creates an editable control with the defaultCodeArea
:
CodeArea codeArea = new CodeArea();
codeArea.setWrapText(true);
codeArea.setLineNumbersEnabled(true);
codeArea.setText("Lorem\nIpsum");
Which results in the following visual representation:
Usage Considerations
CodeArea
extends the RichTextArea
class, meaning most of the functionality works as it does
in the base class.
There are some differences that should be mentioned:
- Model behavior: any direct changes to the styling, such as
applyStyle()
, will be ignored - Line numbers: the
CodeArea
sets theRichTextArea.leftDecoratorProperty()
to support the line numbers, so applications should not set or bind that property.
- Since:
- 24
-
Nested Class Summary
Nested classes/interfaces declared in class jfx.incubator.scene.control.richtext.RichTextArea
RichTextArea.Tag
-
Property Summary
PropertiesTypePropertyDescriptionfinal ObjectProperty
<Font> The font to use for text in theCodeArea
.final BooleanProperty
Determines whether to show line numbers.final DoubleProperty
Defines the vertical space in pixels between lines.final IntegerProperty
The size of a tab stop in spaces.Properties declared in class jfx.incubator.scene.control.richtext.RichTextArea
anchorPosition, caretBlinkPeriod, caretPosition, contentPadding, displayCaret, editable, highlightCurrentParagraph, leftDecorator, model, redoable, rightDecorator, selection, undoable, useContentHeight, useContentWidth, wrapText
Properties declared in class javafx.scene.control.Control
contextMenu, skin, tooltip
Properties declared in class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
Properties declared in class javafx.scene.Parent
needsLayout
Properties declared in class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Field Summary
Fields declared in class jfx.incubator.scene.control.richtext.RichTextArea
styleHandlerRegistry
Fields declared in class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
Fields declared in class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Constructor Summary
ConstructorsConstructorDescriptionCodeArea()
This constructor creates the CodeArea with the defaultCodeTextModel
.CodeArea
(CodeTextModel model) This constructor creates the CodeArea with the specifiedCodeTextModel
. -
Method Summary
Modifier and TypeMethodDescriptionfinal ObjectProperty
<Font> The font to use for text in theCodeArea
.static List
<CssMetaData<? extends Styleable, ?>> Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.final Font
getFont()
Gets the value of thefont
property.final double
Gets the value of thelineSpacing
property.final SyntaxDecorator
This convenience method returns the syntax decorator value in theCodeTextModel
, or null if the model is null.final int
Gets the value of thetabSize
property.final String
getText()
Returns plain text.final boolean
Gets the value of thelineNumbersEnabled
property.final BooleanProperty
Determines whether to show line numbers.final DoubleProperty
Defines the vertical space in pixels between lines.final void
Sets the value of thefont
property.final void
setLineNumbersEnabled
(boolean on) Sets the value of thelineNumbersEnabled
property.final void
setLineSpacing
(double spacing) Sets the value of thelineSpacing
property.final void
This convenience method sets the decorator property in theCodeTextModel
.final void
setTabSize
(int spaces) Sets the value of thetabSize
property.final void
Replaces text in this CodeArea.final IntegerProperty
The size of a tab stop in spaces.Methods declared in class jfx.incubator.scene.control.richtext.RichTextArea
anchorPositionProperty, appendText, appendText, appendText, applyStyle, backspace, caretBlinkPeriodProperty, caretPositionProperty, clear, clearSelection, clearUndoRedo, contentPaddingProperty, copy, copy, createDefaultSkin, cut, delete, deleteParagraph, deleteParagraphStart, deleteWordNextEnd, deleteWordNextStart, deleteWordPrevious, deselect, displayCaretProperty, editableProperty, errorFeedback, execute, executeDefault, extendSelection, getActiveStyleAttributeMap, getAnchorPosition, getCaretBlinkPeriod, getCaretPosition, getContentPadding, getControlCssMetaData, getDocumentEnd, getInputMap, getLeftDecorator, getModel, getParagraphCount, getParagraphEnd, getPlainText, getRightDecorator, getSelection, getStyleHandlerRegistry, getTextPosition, hasNonEmptySelection, highlightCurrentParagraphProperty, insertLineBreak, insertTab, insertText, insertText, isDisplayCaret, isEditable, isHighlightCurrentParagraph, isRedoable, isUndoable, isUseContentHeight, isUseContentWidth, isWrapText, leftDecoratorProperty, modelProperty, moveDocumentEnd, moveDocumentStart, moveDown, moveLeft, moveLineEnd, moveLineStart, moveParagraphDown, moveParagraphEnd, moveParagraphStart, moveParagraphUp, moveRight, moveUp, moveWordLeft, moveWordNextEnd, moveWordNextStart, moveWordPrevious, moveWordRight, pageDown, pageUp, paste, paste, pastePlainText, read, read, redo, redoableProperty, replaceText, replaceText, rightDecoratorProperty, select, select, selectAll, selectDown, selectionProperty, selectLeft, selectPageDown, selectPageUp, selectParagraph, selectParagraphDown, selectParagraphEnd, selectParagraphStart, selectParagraphUp, selectRight, selectToDocumentEnd, selectToDocumentStart, selectToLineEnd, selectToLineStart, selectUp, selectWord, selectWordLeft, selectWordNextEnd, selectWordNextStart, selectWordPrevious, selectWordRight, setCaretBlinkPeriod, setContentPadding, setDisplayCaret, setEditable, setHighlightCurrentParagraph, setLeftDecorator, setModel, setRightDecorator, setStyle, setUseContentHeight, setUseContentWidth, setWrapText, undo, undoableProperty, useContentHeightProperty, useContentWidthProperty, validateModel, wrapTextProperty, write, write
Methods declared in class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, contextMenuProperty, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
Methods declared in class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computePrefHeight, computePrefWidth, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods declared in class javafx.scene.Parent
getBaselineOffset, getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, layoutChildren, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
Methods declared in class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, requestFocusTraversal, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
lineNumbersEnabled
Determines whether to show line numbers. Toggling this property results in changes made to theleftDecorator
property, so the application code should not bind or modify that property.- Default value:
- false
- See Also:
-
tabSize
The size of a tab stop in spaces. Values less than 1 are treated as 1.- Default value:
- 8
- See Also:
-
font
The font to use for text in theCodeArea
.- Default value:
- the Monospaced font with the default size
- See Also:
-
lineSpacing
Defines the vertical space in pixels between lines.- Default value:
- 0
- See Also:
-
-
Constructor Details
-
CodeArea
This constructor creates the CodeArea with the specifiedCodeTextModel
.- Parameters:
model
- the instance ofCodeTextModel
to use
-
CodeArea
public CodeArea()This constructor creates the CodeArea with the defaultCodeTextModel
.
-
-
Method Details
-
setSyntaxDecorator
This convenience method sets the decorator property in theCodeTextModel
. Nothing is done if the model is null.- Parameters:
d
- the syntax decorator- See Also:
-
getSyntaxDecorator
This convenience method returns the syntax decorator value in theCodeTextModel
, or null if the model is null.- Returns:
- the syntax decorator value, or null
-
lineNumbersEnabledProperty
Determines whether to show line numbers. Toggling this property results in changes made to theleftDecorator
property, so the application code should not bind or modify that property.- Default value:
- false
- Returns:
- the line numbers enabled property
- See Also:
-
isLineNumbersEnabled
public final boolean isLineNumbersEnabled()Gets the value of thelineNumbersEnabled
property.- Property description:
- Determines whether to show line numbers.
Toggling this property results in changes made to the
leftDecorator
property, so the application code should not bind or modify that property. - Default value:
- false
- Returns:
- the value of the
lineNumbersEnabled
property - See Also:
-
setLineNumbersEnabled
public final void setLineNumbersEnabled(boolean on) Sets the value of thelineNumbersEnabled
property.- Property description:
- Determines whether to show line numbers.
Toggling this property results in changes made to the
leftDecorator
property, so the application code should not bind or modify that property. - Default value:
- false
- Parameters:
on
- the value for thelineNumbersEnabled
property- See Also:
-
tabSizeProperty
The size of a tab stop in spaces. Values less than 1 are treated as 1.- Default value:
- 8
- Returns:
- the tab size property
- See Also:
-
getTabSize
public final int getTabSize()Gets the value of thetabSize
property.- Property description:
- The size of a tab stop in spaces. Values less than 1 are treated as 1.
- Default value:
- 8
- Returns:
- the value of the
tabSize
property - See Also:
-
setTabSize
public final void setTabSize(int spaces) Sets the value of thetabSize
property.- Property description:
- The size of a tab stop in spaces. Values less than 1 are treated as 1.
- Default value:
- 8
- Parameters:
spaces
- the value for thetabSize
property- See Also:
-
fontProperty
The font to use for text in theCodeArea
.- Default value:
- the Monospaced font with the default size
- Returns:
- the font property
- See Also:
-
setFont
Sets the value of thefont
property.- Property description:
- The font to use for text in the
CodeArea
. - Default value:
- the Monospaced font with the default size
- Parameters:
value
- the value for thefont
property- See Also:
-
getFont
Gets the value of thefont
property.- Property description:
- The font to use for text in the
CodeArea
. - Default value:
- the Monospaced font with the default size
- Returns:
- the value of the
font
property - See Also:
-
lineSpacingProperty
Defines the vertical space in pixels between lines.- Default value:
- 0
- Returns:
- the property instance
- See Also:
-
setLineSpacing
public final void setLineSpacing(double spacing) Sets the value of thelineSpacing
property.- Property description:
- Defines the vertical space in pixels between lines.
- Default value:
- 0
- Parameters:
spacing
- the value for thelineSpacing
property- See Also:
-
getLineSpacing
public final double getLineSpacing()Gets the value of thelineSpacing
property.- Property description:
- Defines the vertical space in pixels between lines.
- Default value:
- 0
- Returns:
- the value of the
lineSpacing
property - See Also:
-
getClassCssMetaData
Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.- Returns:
- the
CssMetaData
-
getText
Returns plain text. This method returns an empty string when the model isnull
.- Returns:
- plain text
-
setText
Replaces text in this CodeArea.The caret gets reset to the start of the document, selection gets cleared, and an undo event gets created.
- Parameters:
text
- the text string
-