Top Description Inners Fields Constructors Methods
javafx.scene.control

public Class TextArea

extends TextInputControl
Class Inheritance
Imports
java.util.AbstractList, .ArrayList, .Collection, .Collections, .List, javafx.beans.InvalidationListener, javafx.beans.property.BooleanProperty, .DoubleProperty, .IntegerProperty, .SimpleDoubleProperty, javafx.collections.ListChangeListener, .ObservableList, javafx.css.CssMetaData, .StyleConverter, .StyleableBooleanProperty, .StyleableIntegerProperty, .StyleableProperty, .Styleable, com.sun.javafx.collections.ListListenerHelper, .NonIterableChange, javafx.css.converter.SizeConverter, javafx.scene.control.skin.TextAreaSkin, javafx.scene.AccessibleRole

Text input component that allows a user to enter multiple lines of plain text. Unlike in previous releases of JavaFX, support for single line input is not available as part of the TextArea control, however this is the sole-purpose of the TextField control. Additionally, if you want a form of rich-text editing, there is also the HTMLEditor control.

TextArea supports the notion of showing prompt text to the user when there is no text already in the TextArea (either via the user, or set programmatically). This is a useful way of informing the user as to what is expected in the text area, without having to resort to tooltips or on-screen labels.

Example:

 var textArea = new TextArea("Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
       + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim "
       + "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip "
       + "ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
       + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat "
       + "cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
textArea.setWrapText(true);
Image of the TextArea control
Since
JavaFX 2.0
See Also
TextField

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final int
public static final int
public static final int
DEFAULT_PREF_ROW_COUNT

The default value for prefRowCount.

private IntegerProperty
prefColumnCount

The preferred number of text columns.

private IntegerProperty
prefRowCount

The preferred number of text rows.

private DoubleProperty
scrollLeft

The number of pixels by which the content is horizontally scrolled.

private DoubleProperty
scrollTop

The number of pixels by which the content is vertically scrolled.

private BooleanProperty
wrapText

If a run of text exceeds the width of the TextArea, then this variable indicates whether the text should wrap onto another line.

Constructor Summary

AccessConstructor and Description
public
TextArea()

Creates a TextArea with empty text content.

public
TextArea(String
A string for text content.
text
)

Creates a TextArea with initial text content.

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

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

pack-priv String
public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.control.TextInputControl.getClassCssMetaData.

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

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

Overrides javafx.scene.control.TextInputControl.getControlCssMetaData.

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

public ObservableList<CharSequence>

Returns:

an unmodifiable list of the character sequences that back the text area's content
getParagraphs
()

Returns an unmodifiable list of the character sequences that back the text area's content.

public final int
public final int
public final double
public final double
public final boolean
public final IntegerProperty
public final IntegerProperty
public final DoubleProperty
public final DoubleProperty
public final void
setPrefColumnCount(int value)

public final void
setPrefRowCount(int value)

public final void
setScrollLeft(double value)

public final void
setScrollTop(double value)

public final void
setWrapText(boolean value)

pack-priv final void
public final BooleanProperty
Inherited from javafx.scene.control.TextInputControl:
anchorPropertyappendTextbackwardcancelEditcaretPositionPropertyclearcommitValuecontainsInvalidCharacterscopycutdeleteNextChardeletePreviousChardeleteTextdeleteTextdeselecteditablePropertyendendOfNextWordexecuteAccessibleActionextendSelectionfilterInputfontPropertyforwardgetAnchorgetCaretPositiongetContentgetFontgetLengthgetPromptTextgetSelectedTextgetSelectiongetTextgetTextgetTextFormatterhomeinsertTextisEditableisRedoableisUndoablelengthPropertynextWordpastepositionCaretpreviousWordpromptTextPropertyqueryAccessibleAttributeredoredoablePropertyreplaceSelectionreplaceTextreplaceTextselectAllselectBackwardselectedTextPropertyselectEndselectEndOfNextWordselectForwardselectHomeselectionPropertyselectNextWordselectPositionCaretselectPreviousWordselectRangesetEditablesetFontsetPromptTextsetTextsetTextFormattertextFormatterPropertytextPropertyundoundoableProperty

Field Detail

DEFAULT_PARAGRAPH_CAPACITYback to summary
private static final int DEFAULT_PARAGRAPH_CAPACITY
DEFAULT_PREF_COLUMN_COUNTback to summary
public static final int DEFAULT_PREF_COLUMN_COUNT

The default value for prefColumnCount.

DEFAULT_PREF_ROW_COUNTback to summary
public static final int DEFAULT_PREF_ROW_COUNT

The default value for prefRowCount.

prefColumnCountback to summary
private IntegerProperty prefColumnCount

The preferred number of text columns. This is used for calculating the TextArea's preferred width.

prefRowCountback to summary
private IntegerProperty prefRowCount

The preferred number of text rows. This is used for calculating the TextArea's preferred height.

scrollLeftback to summary
private DoubleProperty scrollLeft

The number of pixels by which the content is horizontally scrolled.

scrollTopback to summary
private DoubleProperty scrollTop

The number of pixels by which the content is vertically scrolled.

wrapTextback to summary
private BooleanProperty wrapText

If a run of text exceeds the width of the TextArea, then this variable indicates whether the text should wrap onto another line.

Constructor Detail

TextAreaback to summary
public TextArea()

Creates a TextArea with empty text content.

TextAreaback to summary
public TextArea(String text)

Creates a TextArea with initial text content.

Parameters
text:String

A string for text content.

Method Detail

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
filterInputback to summary
pack-priv String filterInput(String text)

Overrides javafx.scene.control.TextInputControl.filterInput.

Annotations
@Override
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.TextInputControl.getClassCssMetaData.

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

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

the CssMetaData

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

Overrides javafx.scene.control.TextInputControl.getControlCssMetaData.

Doc from javafx.scene.control.TextInputControl.getControlCssMetaData.

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

Annotations
@Override
Since
JavaFX 8.0
getParagraphsback to summary
public ObservableList<CharSequence> getParagraphs()

Returns an unmodifiable list of the character sequences that back the text area's content.

Returns:ObservableList<CharSequence>

an unmodifiable list of the character sequences that back the text area's content

getPrefColumnCountback to summary
public final int getPrefColumnCount()
getPrefRowCountback to summary
public final int getPrefRowCount()
getScrollLeftback to summary
public final double getScrollLeft()
getScrollTopback to summary
public final double getScrollTop()
isWrapTextback to summary
public final boolean isWrapText()
prefColumnCountPropertyback to summary
public final IntegerProperty prefColumnCountProperty()
prefRowCountPropertyback to summary
public final IntegerProperty prefRowCountProperty()
scrollLeftPropertyback to summary
public final DoubleProperty scrollLeftProperty()
scrollTopPropertyback to summary
public final DoubleProperty scrollTopProperty()
setPrefColumnCountback to summary
public final void setPrefColumnCount(int value)
setPrefRowCountback to summary
public final void setPrefRowCount(int value)
setScrollLeftback to summary
public final void setScrollLeft(double value)
setScrollTopback to summary
public final void setScrollTop(double value)
setWrapTextback to summary
public final void setWrapText(boolean value)
textUpdatedback to summary
pack-priv final void textUpdated()

Overrides javafx.scene.control.TextInputControl.textUpdated.

Annotations
@Override
wrapTextPropertyback to summary
public final BooleanProperty wrapTextProperty()
javafx.scene.control back to summary

private final Class TextArea.ParagraphList

extends AbstractList<CharSequence>
implements ObservableList<CharSequence>
Class Inheritance
All Implemented Interfaces
javafx.collections.ObservableList, javafx.beans.Observable, java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable

Field Summary

Modifier and TypeField and Description
private TextArea.TextAreaContent
private ListListenerHelper<CharSequence>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
addAll(Collection<? extends CharSequence> paragraphs)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

public boolean
addAll(CharSequence... paragraphs)

Implements javafx.collections.ObservableList.addAll.

A convenience method for var-arg addition of elements.

public void
addListener(ListChangeListener<? super CharSequence> listener)

Implements javafx.collections.ObservableList.addListener.

Add a listener to this observable list.

public void
addListener(InvalidationListener listener)

Implements javafx.beans.Observable.addListener.

Adds an InvalidationListener which will be notified whenever the Observable becomes invalid.

public CharSequence
get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.

public void
remove(int from, int to)

Implements javafx.collections.ObservableList.remove.

A simplified way of calling sublist(from, to).clear().

public boolean
removeAll(CharSequence... elements)

Implements javafx.collections.ObservableList.removeAll.

A convenience method for var-arg usage of the removeAll method.

public void
removeListener(ListChangeListener<? super CharSequence> listener)

Implements javafx.collections.ObservableList.removeListener.

Tries to remove a listener from this observable list.

public void
removeListener(InvalidationListener listener)

Implements javafx.beans.Observable.removeListener.

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

public boolean
retainAll(CharSequence... elements)

Implements javafx.collections.ObservableList.retainAll.

A convenience method for var-arg usage of the retainAll method.

public boolean
setAll(Collection<? extends CharSequence> paragraphs)

Implements javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all elements from the collection.

public boolean
setAll(CharSequence... paragraphs)

Implements javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all the elements passed as var-args.

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.

Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

contentback to summary
private TextArea.TextAreaContent content
listenerHelperback to summary
private ListListenerHelper<CharSequence> listenerHelper

Constructor Detail

ParagraphListback to summary
private ParagraphList()

Method Detail

addAllback to summary
public boolean addAll(Collection<? extends CharSequence> paragraphs)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Doc from java.util.List.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Annotations
@Override
addAllback to summary
public boolean addAll(CharSequence... paragraphs)

Implements javafx.collections.ObservableList.addAll.

Doc from javafx.collections.ObservableList.addAll.

A convenience method for var-arg addition of elements.

Annotations
@Override
addListenerback to summary
public void addListener(ListChangeListener<? super CharSequence> listener)

Implements javafx.collections.ObservableList.addListener.

Doc from javafx.collections.ObservableList.addListener.

Add a listener to this observable list.

Annotations
@Override
addListenerback to summary
public void addListener(InvalidationListener listener)

Implements javafx.beans.Observable.addListener.

Doc from javafx.beans.Observable.addListener.

Adds an InvalidationListener which will be notified whenever the Observable becomes invalid. If the same listener is added more than once, then it will be notified more than once. That is, no check is made to ensure uniqueness.

Note that the same actual InvalidationListener instance may be safely registered for different Observables.

The Observable stores a strong reference to the listener which will prevent the listener from being garbage collected and may result in a memory leak. It is recommended to either unregister a listener by calling removeListener after use or to use an instance of WeakInvalidationListener avoid this situation.

Annotations
@Override
getback to summary
public CharSequence get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Annotations
@Override
removeback to summary
public void remove(int from, int to)

Implements javafx.collections.ObservableList.remove.

Doc from javafx.collections.ObservableList.remove.

A simplified way of calling sublist(from, to).clear(). As this is a common operation, ObservableList has this method for convenient usage.

Annotations
@Override
removeAllback to summary
public boolean removeAll(CharSequence... elements)

Implements javafx.collections.ObservableList.removeAll.

Doc from javafx.collections.ObservableList.removeAll.

A convenience method for var-arg usage of the removeAll method.

Annotations
@Override
removeListenerback to summary
public void removeListener(ListChangeListener<? super CharSequence> listener)

Implements javafx.collections.ObservableList.removeListener.

Doc from javafx.collections.ObservableList.removeListener.

Tries to remove a listener from this observable list. If the listener is not attached to this list, nothing happens.

Annotations
@Override
removeListenerback to summary
public void removeListener(InvalidationListener listener)

Implements javafx.beans.Observable.removeListener.

Doc from javafx.beans.Observable.removeListener.

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed.

Annotations
@Override
retainAllback to summary
public boolean retainAll(CharSequence... elements)

Implements javafx.collections.ObservableList.retainAll.

Doc from javafx.collections.ObservableList.retainAll.

A convenience method for var-arg usage of the retainAll method.

Annotations
@Override
setAllback to summary
public boolean setAll(Collection<? extends CharSequence> paragraphs)

Implements javafx.collections.ObservableList.setAll.

Doc from javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all elements from the collection.

Annotations
@Override
setAllback to summary
public boolean setAll(CharSequence... paragraphs)

Implements javafx.collections.ObservableList.setAll.

Doc from javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all the elements passed as var-args.

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
javafx.scene.control back to summary

private final Class TextArea.ParagraphListChange

extends NonIterableChange<CharSequence>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private List<CharSequence>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected int[]
getPermutation()

Overrides com.sun.javafx.collections.NonIterableChange.getPermutation.

If this change is a permutation, it returns an integer array that describes the permutation.

public List<CharSequence>
getRemoved()

Implements abstract javafx.collections.ListChangeListener.Change.getRemoved.

An immutable list of removed/replaced elements.

Inherited from com.sun.javafx.collections.NonIterableChange:
checkStategetFromgetTonextresettoString

Field Detail

removedback to summary
private List<CharSequence> removed

Constructor Detail

ParagraphListChangeback to summary
protected ParagraphListChange(ObservableList<CharSequence> list, int from, int to, List<CharSequence> removed)

Method Detail

getPermutationback to summary
protected int[] getPermutation()

Overrides com.sun.javafx.collections.NonIterableChange.getPermutation.

Doc from javafx.collections.ListChangeListener.Change.getPermutation.

If this change is a permutation, it returns an integer array that describes the permutation. This array maps directly from the previous indexes to the new ones. This method is not publicly accessible and therefore can return an array safely. The 0 index of the array corresponds to index getFrom() of the list. The same applies for the last index and getTo(). The method is used by wasPermutated() and getPermutation(int) methods.

Annotations
@Override
getRemovedback to summary
public List<CharSequence> getRemoved()

Implements abstract javafx.collections.ListChangeListener.Change.getRemoved.

Doc from javafx.collections.ListChangeListener.Change.getRemoved.

An immutable list of removed/replaced elements. If no elements were removed from the list, an empty list is returned.

Annotations
@Override
javafx.scene.control back to summary

private Class TextArea.StyleableProperties

extends Object
Class Inheritance

Field Summary

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PREF_COLUMN_COUNTback to summary
private static final CssMetaData<TextArea, Number> PREF_COLUMN_COUNT
PREF_ROW_COUNTback to summary
private static final CssMetaData<TextArea, Number> PREF_ROW_COUNT
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
WRAP_TEXTback to summary
private static final CssMetaData<TextArea, Boolean> WRAP_TEXT

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()
javafx.scene.control back to summary

private final Class TextArea.TextAreaContent

extends ContentBase
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private final TextArea.ParagraphList
private final List<StringBuilder>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
delete(int start, int end, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.delete.

Removes a sequence of characters from the content.

private void
fireParagraphListChangeEvent(int from, int to, List<CharSequence> removed)

public String
get(int start, int end)

Implements javafx.scene.control.TextInputControl.Content.get.

Retrieves a subset of the content.

public String
get()

Implements javafx.beans.value.ObservableObjectValue.get.

Returns the current value of this ObservableObjectValue<T>.

public String
getValue()

Implements javafx.beans.value.ObservableValue.getValue.

Returns the current value of this ObservableValue

public void
insert(int index, String text, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.insert.

Inserts a sequence of characters into the content.

public int
length()

Implements javafx.scene.control.TextInputControl.Content.length.

Returns the number of characters represented by the content.

Inherited from javafx.scene.control.TextInputControl.ContentBase:
addListeneraddListenerfireValueChangedEventremoveListenerremoveListener

Field Detail

contentLengthback to summary
private int contentLength
paragraphListback to summary
private final TextArea.ParagraphList paragraphList
paragraphsback to summary
private final List<StringBuilder> paragraphs

Constructor Detail

TextAreaContentback to summary
private TextAreaContent()

Method Detail

deleteback to summary
public void delete(int start, int end, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.delete.

Doc from javafx.scene.control.TextInputControl.Content.delete.

Removes a sequence of characters from the content.

Annotations
@Override
fireParagraphListChangeEventback to summary
private void fireParagraphListChangeEvent(int from, int to, List<CharSequence> removed)
getback to summary
public String get(int start, int end)

Implements javafx.scene.control.TextInputControl.Content.get.

Doc from javafx.scene.control.TextInputControl.Content.get.

Retrieves a subset of the content.

Annotations
@Override
getback to summary
public String get()

Implements javafx.beans.value.ObservableObjectValue.get.

Doc from javafx.beans.value.ObservableObjectValue.get.

Returns the current value of this ObservableObjectValue<T>.

Annotations
@Override
getValueback to summary
public String getValue()

Implements javafx.beans.value.ObservableValue.getValue.

Doc from javafx.beans.value.ObservableValue.getValue.

Returns the current value of this ObservableValue

Annotations
@Override
insertback to summary
public void insert(int index, String text, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.insert.

Doc from javafx.scene.control.TextInputControl.Content.insert.

Inserts a sequence of characters into the content.

Annotations
@Override
@SuppressWarnings:unchecked
lengthback to summary
public int length()

Implements javafx.scene.control.TextInputControl.Content.length.

Doc from javafx.scene.control.TextInputControl.Content.length.

Returns the number of characters represented by the content.

Annotations
@Override