Top Description Inners Fields Constructors Methods
jfx.incubator.scene.control.richtext

public Class CodeArea

extends RichTextArea
Class Inheritance
Imports
java.io.IOException, .UncheckedIOException, java.util.List, javafx.beans.property.BooleanProperty, .DoubleProperty, .IntegerProperty, .ObjectProperty, .SimpleBooleanProperty, javafx.beans.value.WritableValue, javafx.css.CssMetaData, .FontCssMetaData, .StyleOrigin, .Styleable, .StyleableDoubleProperty, .StyleableIntegerProperty, .StyleableObjectProperty, .StyleableProperty, javafx.css.converter.SizeConverter, javafx.scene.AccessibleAttribute, .Node, javafx.scene.control.Labeled, javafx.scene.text.Font, com.sun.jfx.incubator.scene.control.richtext.Params, .StringBuilderStyledOutput, com.sun.jfx.incubator.scene.control.richtext.util.RichUtils, jfx.incubator.scene.control.richtext.model.CodeTextModel, .StyledTextModel, jfx.incubator.scene.control.richtext.skin.CodeAreaSkin, .RichTextAreaSkin

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 default CodeArea:
CodeArea codeArea = new CodeArea();
  codeArea.setWrapText(true);
  codeArea.setLineNumbersEnabled(true);
  codeArea.setText("Lorem\nIpsum");
Which results in the following visual representation:

Image of the CodeArea control

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:
Since
24

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CodeArea.StyleableProperties

styleable properties

Field Summary

Modifier and TypeField and Description
private StyleableObjectProperty<Font>
private String
private BooleanProperty
private StyleableDoubleProperty
private StyleableIntegerProperty
Inherited from jfx.incubator.scene.control.richtext.RichTextArea:
styleHandlerRegistry

Constructor Summary

AccessConstructor and Description
public
CodeArea(CodeTextModel
the instance of CodeTextModel to use
model
)

This constructor creates the CodeArea with the specified CodeTextModel.

public
CodeArea()

This constructor creates the CodeArea with the default CodeTextModel.

Method Summary

Modifier and TypeMethod and Description
private CodeTextModel
protected RichTextAreaSkin
createDefaultSkin()

Overrides jfx.incubator.scene.control.richtext.RichTextArea.createDefaultSkin.

Create a new instance of the default skin for this control.

private static Font
public final ObjectProperty<Font>

Returns:

the font property
fontProperty
()

The font to use for text in the CodeArea.

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides jfx.incubator.scene.control.richtext.RichTextArea.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides jfx.incubator.scene.control.richtext.RichTextArea.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final Font
public final double
public final SyntaxDecorator

Returns:

the syntax decorator value, or null
getSyntaxDecorator
()

This convenience method returns the syntax decorator value in the CodeTextModel, or null if the model is null.

public final int
public final String

Returns:

plain text
getText
()

Returns plain text.

public final boolean
public final BooleanProperty

Returns:

the line numbers enabled property
lineNumbersEnabledProperty
()

Determines whether to show line numbers.

public final DoubleProperty

Returns:

the property instance
lineSpacingProperty
()

Defines the vertical space in pixels between lines.

public Object
queryAccessibleAttribute(AccessibleAttribute
the requested attribute
attribute
,
Object...
optional list of parameters
parameters
)

Overrides jfx.incubator.scene.control.richtext.RichTextArea.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

public final void
setFont(Font value)

public final void
public final void
setLineSpacing(double spacing)

public final void
setSyntaxDecorator(SyntaxDecorator
the syntax decorator
d
)

This convenience method sets the decorator property in the CodeTextModel.

public final void
setTabSize(int spaces)

public final void
setText(String
the text string
text
)

Replaces text in this CodeArea.

public final IntegerProperty

Returns:

the tab size property
tabSizeProperty
()

The size of a tab stop in spaces.

protected void
validateModel(StyledTextModel
the model (can be null)
m
)

Overrides jfx.incubator.scene.control.richtext.RichTextArea.validateModel.

Validates the model property value.

Inherited from jfx.incubator.scene.control.richtext.RichTextArea:
anchorPositionPropertyappendTextappendTextappendTextapplyStylebackspacecaretBlinkPeriodPropertycaretPositionPropertyclearclearSelectionclearUndoRedocontentPaddingPropertycopycopycutdeletedeleteParagraphdeleteParagraphStartdeleteWordNextEnddeleteWordNextStartdeleteWordPreviousdeselectdisplayCaretPropertyeditablePropertyerrorFeedbackexecuteexecuteAccessibleActionexecuteDefaultextendSelectiongetActiveStyleAttributeMapgetAnchorPositiongetCaretBlinkPeriodgetCaretPositiongetContentPaddinggetDocumentEndgetInputMapgetLeftDecoratorgetModelgetParagraphCountgetParagraphEndgetPlainTextgetRightDecoratorgetSelectiongetStyleHandlerRegistrygetTextPositionhasNonEmptySelectionhighlightCurrentParagraphPropertyinsertLineBreakinsertTabinsertTextinsertTextisDisplayCaretisEditableisHighlightCurrentParagraphisRedoableisUndoableisUseContentHeightisUseContentWidthisWrapTextleftDecoratorPropertymodelPropertymoveDocumentEndmoveDocumentStartmoveDownmoveLeftmoveLineEndmoveLineStartmoveParagraphDownmoveParagraphEndmoveParagraphStartmoveParagraphUpmoveRightmoveUpmoveWordLeftmoveWordNextEndmoveWordNextStartmoveWordPreviousmoveWordRightpageDownpageUppastepastepastePlainTextreadreadredoredoablePropertyreplaceTextreplaceTextrightDecoratorPropertyselectselectselectAllselectDownselectionPropertyselectLeftselectPageDownselectPageUpselectParagraphselectParagraphDownselectParagraphEndselectParagraphStartselectParagraphUpselectRightselectToDocumentEndselectToDocumentStartselectToLineEndselectToLineStartselectUpselectWordselectWordLeftselectWordNextEndselectWordNextStartselectWordPreviousselectWordRightsetCaretBlinkPeriodsetContentPaddingsetDisplayCaretsetEditablesetHighlightCurrentParagraphsetLeftDecoratorsetModelsetRightDecoratorsetStylesetUseContentHeightsetUseContentWidthsetWrapTextundoundoablePropertyuseContentHeightPropertyuseContentWidthPropertyvflowwrapTextPropertywritewrite

Field Detail

fontback to summary
private StyleableObjectProperty<Font> font
fontStyleback to summary
private String fontStyle
lineNumbersback to summary
private BooleanProperty lineNumbers
lineSpacingback to summary
private StyleableDoubleProperty lineSpacing
tabSizeback to summary
private StyleableIntegerProperty tabSize

Constructor Detail

CodeAreaback to summary
public CodeArea(CodeTextModel model)

This constructor creates the CodeArea with the specified CodeTextModel.

Parameters
model:CodeTextModel

the instance of CodeTextModel to use

CodeAreaback to summary
public CodeArea()

This constructor creates the CodeArea with the default CodeTextModel.

Method Detail

codeModelback to summary
private CodeTextModel codeModel()
createDefaultSkinback to summary
protected RichTextAreaSkin createDefaultSkin()

Overrides jfx.incubator.scene.control.richtext.RichTextArea.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Returns:RichTextAreaSkin

new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.

Annotations
@Override
defaultFontback to summary
private static Font defaultFont()
fontPropertyback to summary
public final ObjectProperty<Font> fontProperty()

The font to use for text in the CodeArea.

Returns:ObjectProperty<Font>

the font property

Default Value
the Monospaced font with the default size
See Also
Font#font(String, double)
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides jfx.incubator.scene.control.richtext.RichTextArea.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

getControlCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides jfx.incubator.scene.control.richtext.RichTextArea.getControlCssMetaData.

Doc from javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Returns:List<CssMetaData<? extends Styleable, ?>>

the unmodifiable list of the control's CSS-styleable properties

Annotations
@Override
getFontback to summary
public final Font getFont()
getLineSpacingback to summary
public final double getLineSpacing()
getSyntaxDecoratorback to summary
public final SyntaxDecorator getSyntaxDecorator()

This convenience method returns the syntax decorator value in the CodeTextModel, or null if the model is null.

Returns:SyntaxDecorator

the syntax decorator value, or null

getTabSizeback to summary
public final int getTabSize()
getTextback to summary
public final String getText()

Returns plain text. This method returns an empty string when the model is null.

Returns:String

plain text

isLineNumbersEnabledback to summary
public final boolean isLineNumbersEnabled()
lineNumbersEnabledPropertyback to summary
public final BooleanProperty lineNumbersEnabledProperty()

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.

Returns:BooleanProperty

the line numbers enabled property

Default Value
false
lineSpacingPropertyback to summary
public final DoubleProperty lineSpacingProperty()

Defines the vertical space in pixels between lines.

Returns:DoubleProperty

the property instance

Default Value
0
queryAccessibleAttributeback to summary
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides jfx.incubator.scene.control.richtext.RichTextArea.queryAccessibleAttribute.

Doc from javafx.scene.control.Control.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.

Parameters
attribute:AccessibleAttribute

Doc from javafx.scene.Node.queryAccessibleAttribute.

the requested attribute

parameters:Object[]

Doc from javafx.scene.Node.queryAccessibleAttribute.

optional list of parameters

Returns:Object

Doc from javafx.scene.Node.queryAccessibleAttribute.

the value for the requested attribute

Annotations
@Override
setFontback to summary
public final void setFont(Font value)
setLineNumbersEnabledback to summary
public final void setLineNumbersEnabled(boolean on)
setLineSpacingback to summary
public final void setLineSpacing(double spacing)
setSyntaxDecoratorback to summary
public final void setSyntaxDecorator(SyntaxDecorator d)

This convenience method sets the decorator property in the CodeTextModel. Nothing is done if the model is null.

Parameters
d:SyntaxDecorator

the syntax decorator

See Also
CodeTextModel#setDecorator(SyntaxDecorator)
setTabSizeback to summary
public final void setTabSize(int spaces)
setTextback to summary
public final void setText(String text)

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:String

the text string

tabSizePropertyback to summary
public final IntegerProperty tabSizeProperty()

The size of a tab stop in spaces. Values less than 1 are treated as 1.

Returns:IntegerProperty

the tab size property

Default Value
8
validateModelback to summary
protected void validateModel(StyledTextModel m)

Overrides jfx.incubator.scene.control.richtext.RichTextArea.validateModel.

Doc from jfx.incubator.scene.control.richtext.RichTextArea.validateModel.

Validates the model property value. The subclass should override this method if it restricts the type of model that is supported, and throw an IllegalArgumentException if the model is not supported. A null value should always be acceptable and never generate an exception.

Parameters
m:StyledTextModel

the model (can be null)

Annotations
@Override
jfx.incubator.scene.control.richtext back to summary

private Class CodeArea.StyleableProperties

extends Object
Class Inheritance
  • java.lang.Object
  • jfx.incubator.scene.control.richtext.CodeArea.StyleableProperties

styleable properties

Field Summary

Modifier and TypeField and Description
private static final FontCssMetaData<CodeArea>
private static final CssMetaData<CodeArea, Number>
private static final List<CssMetaData<? extends Styleable, ?>>
private static final CssMetaData<CodeArea, Number>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FONTback to summary
private static final FontCssMetaData<CodeArea> FONT
LINE_SPACINGback to summary
private static final CssMetaData<CodeArea, Number> LINE_SPACING
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
TAB_SIZEback to summary
private static final CssMetaData<CodeArea, Number> TAB_SIZE

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()