Top Description Inners Fields Constructors Methods
com.dlsc.gemsfx

public Class TextView

extends Control
Class Inheritance
Imports
com.dlsc.gemsfx.skins.TextViewSkin, javafx.beans.property.BooleanProperty, .ObjectProperty, .ReadOnlyStringProperty, .ReadOnlyStringWrapper, .SimpleBooleanProperty, .SimpleStringProperty, .StringProperty, javafx.collections.MapChangeListener, javafx.css.CssMetaData, .Styleable, .StyleableObjectProperty, .StyleableProperty, javafx.css.converter.PaintConverter, javafx.geometry.Orientation, javafx.scene.control.ContextMenu, .Control, .MenuItem, .Skin, javafx.scene.input.Clipboard, .ClipboardContent, javafx.scene.layout.Region, javafx.scene.paint.Color, .Paint, java.util.ArrayList, .Collections, .List, .Objects

A text view that allows you to display multiline text and supports the selection of text, which can then be copied to the clipboard. The user can copy the selected text via the OS-specific shortcut for copying content (for example, CTRL-C on Windows or Command-C on Mac). Additionally, a context menu is available for copying.

The user can select text by pressing and dragging the mouse, or by double clicking on a word. A triple click selects an entire paragraph.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final BooleanProperty
private final ObjectProperty<Paint>
highlightFill

Defines the Paint used for the background of the selection highlight.

private final ObjectProperty<Paint>
highlightStroke

Defines the Paint used for the stroke (outline) of the selection highlight.

private final ObjectProperty<Paint>
highlightTextFill

Defines the Paint used for the foreground (the text itself) of selected text.

private final ReadOnlyStringWrapper
private final StringProperty

Constructor Summary

AccessConstructor and Description
public
TextView()

Constructs a new text view.

public
TextView(String
The initial text
text
)

Constructs a new text view.

Method Summary

Modifier and TypeMethod and Description
public void
copyAll()

Copy the entire text to the clipboard.

public void
copySelection()

Copy the text to the clipboard.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

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

public final BooleanProperty

Returns:

the "disable selection by mouse clicks" property
disableTextSelectionByMouseClicksProperty
()

The text view allows the user to select text elements by double or tripple clicking on it.

private void
doCopy(String text)

public static List<CssMetaData<? extends Styleable, ?>>
getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

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

public Orientation
getContentBias()

Overrides javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes.

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

Overrides javafx.scene.control.Control.getControlCssMetaData.

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

public final Paint
public final Paint
public final Paint
public final String

Returns:

The String property.
getSelectedText
()

String property used to save selected skin text

public final String
public String
getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method.

public final ObjectProperty<Paint>

Returns:

the highlight fill property.
highlightFillProperty
()

The property for the Paint used for the background of the selection highlight.

public final ObjectProperty<Paint>

Returns:

the highlight stroke property.
highlightStrokeProperty
()

The property for the Paint used for the stroke (outline) of the selection highlight.

public final ObjectProperty<Paint>

Returns:

the highlight text fill property.
highlightTextFillProperty
()

The property for the Paint used for the foreground (the text itself) of selected text.

public final boolean
public final ReadOnlyStringProperty
public final void
setDisableTextSelectionByMouseClicks(boolean disableTextSelectionByMouseClicks)

public final void
setHighlightFill(Paint
the highlight fill
value
)

The fill Paint used for the background of selected text.

public final void
setHighlightStroke(Paint
the paint to use for the selection highlight's stroke.
value
)

Sets the Paint to be used for the stroke (outline) of the selection highlight.

public final void
setHighlightTextFill(Paint
the highlight text fill
value
)

The fill Paint used for the foreground of selected text.

public final void
public final StringProperty

Returns:

the text shown by the control
textProperty
()

Stores the text displayed by the view.

Inherited from javafx.scene.control.Control:
computeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthcontextMenuPropertyexecuteAccessibleActiongetBaselineOffsetgetContextMenugetCssMetaDatagetInitialFocusTraversablegetSkingetTooltipisResizablelayoutChildrenqueryAccessibleAttributesetContextMenusetSkinsetTooltipskinPropertytooltipProperty

Field Detail

disableTextSelectionByMouseClicksback to summary
private final BooleanProperty disableTextSelectionByMouseClicks
highlightFillback to summary
private final ObjectProperty<Paint> highlightFill

Defines the Paint used for the background of the selection highlight. This is the color or gradient that fills the area behind the selected text.

highlightStrokeback to summary
private final ObjectProperty<Paint> highlightStroke

Defines the Paint used for the stroke (outline) of the selection highlight. This is the color or gradient for the border around the selected text area.

highlightTextFillback to summary
private final ObjectProperty<Paint> highlightTextFill

Defines the Paint used for the foreground (the text itself) of selected text. This is the color of the text characters when they are part of a selection.

selectedTextback to summary
private final ReadOnlyStringWrapper selectedText
textback to summary
private final StringProperty text

Constructor Detail

TextViewback to summary
public TextView()

Constructs a new text view.

TextViewback to summary
public TextView(String text)

Constructs a new text view.

Parameters
text:String

The initial text

Method Detail

copyAllback to summary
public void copyAll()

Copy the entire text to the clipboard. This method is intentionally non-final so that applications can implement their own logic.

copySelectionback to summary
public void copySelection()

Copy the text to the clipboard. This method is intentionally non-final so that applications can implement their own logic.

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.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(...).

Annotations
@Override
disableTextSelectionByMouseClicksPropertyback to summary
public final BooleanProperty disableTextSelectionByMouseClicksProperty()

The text view allows the user to select text elements by double or tripple clicking on it. This property can be used to disable this behavior.

Returns:BooleanProperty

the "disable selection by mouse clicks" property

doCopyback to summary
private void doCopy(String text)
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

Doc from javafx.scene.control.Control.getClassCssMetaData.

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

getContentBiasback to summary
public Orientation getContentBias()

Overrides javafx.scene.Node.getContentBias.

Doc from javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes. If the node type has no bias, returns null. If the node is resizable and it's height depends on its width, returns HORIZONTAL, else if its width depends on its height, returns VERTICAL.

Resizable subclasses should override this method to return an appropriate value.

Annotations
@Override
getControlCssMetaDataback to summary
protected List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

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

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

Annotations
@Override
getHighlightFillback to summary
public final Paint getHighlightFill()
getHighlightStrokeback to summary
public final Paint getHighlightStroke()
getHighlightTextFillback to summary
public final Paint getHighlightTextFill()
getSelectedTextback to summary
public final String getSelectedText()

String property used to save selected skin text

Returns:String

The String property.

getTextback to summary
public final String getText()
getUserAgentStylesheetback to summary
public String getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

Doc from javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. These styles are used in addition to whatever user-agent stylesheets are in use. This provides a mechanism for third parties to introduce styles for custom controls.

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.

Subclasses overriding this method should not assume any particular implementation approach as to the number and frequency with which it is called. For this reason, attempting any kind of dynamic implementation (i.e. returning different user agent stylesheet values) based on some state change is highly discouraged, as there is no guarantee when, or even if, this method will be called. Some JavaFX CSS implementations may choose to cache this response for an indefinite period of time, and therefore there should be no expectation around when this method is called.



package com.example.javafx.app;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {

    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
Annotations
@Override
highlightFillPropertyback to summary
public final ObjectProperty<Paint> highlightFillProperty()

The property for the Paint used for the background of the selection highlight. This is the color or gradient that fills the area behind the selected text.

Returns:ObjectProperty<Paint>

the highlight fill property.

highlightStrokePropertyback to summary
public final ObjectProperty<Paint> highlightStrokeProperty()

The property for the Paint used for the stroke (outline) of the selection highlight. This is the color or gradient for the border around the selected text area. The default value is Color.TRANSPARENT.

Returns:ObjectProperty<Paint>

the highlight stroke property.

highlightTextFillPropertyback to summary
public final ObjectProperty<Paint> highlightTextFillProperty()

The property for the Paint used for the foreground (the text itself) of selected text. This is the color of the text characters when they are part of a selection.

Returns:ObjectProperty<Paint>

the highlight text fill property.

isDisableTextSelectionByMouseClicksback to summary
public final boolean isDisableTextSelectionByMouseClicks()
selectedTextPropertyback to summary
public final ReadOnlyStringProperty selectedTextProperty()
setDisableTextSelectionByMouseClicksback to summary
public final void setDisableTextSelectionByMouseClicks(boolean disableTextSelectionByMouseClicks)
setHighlightFillback to summary
public final void setHighlightFill(Paint value)

The fill Paint used for the background of selected text.

Parameters
value:Paint

the highlight fill

setHighlightStrokeback to summary
public final void setHighlightStroke(Paint value)

Sets the Paint to be used for the stroke (outline) of the selection highlight.

Parameters
value:Paint

the paint to use for the selection highlight's stroke.

setHighlightTextFillback to summary
public final void setHighlightTextFill(Paint value)

The fill Paint used for the foreground of selected text.

Parameters
value:Paint

the highlight text fill

setTextback to summary
public final void setText(String text)
textPropertyback to summary
public final StringProperty textProperty()

Stores the text displayed by the view.

Returns:StringProperty

the text shown by the control

com.dlsc.gemsfx back to summary

private Class TextView.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<TextView, Paint>
private static final CssMetaData<TextView, Paint>
private static final CssMetaData<TextView, Paint>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HIGHLIGHT_FILLback to summary
private static final CssMetaData<TextView, Paint> HIGHLIGHT_FILL
HIGHLIGHT_STROKEback to summary
private static final CssMetaData<TextView, Paint> HIGHLIGHT_STROKE
HIGHLIGHT_TEXT_FILLback to summary
private static final CssMetaData<TextView, Paint> HIGHLIGHT_TEXT_FILL
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()