org.fxmisc.richtext.StyleClassedTextArea Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
Rich-text area for JavaFX
package org.fxmisc.richtext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* Text area that uses style classes to define style of text segments.
*/
public class StyleClassedTextArea extends StyledTextArea> {
public StyleClassedTextArea(boolean preserveStyle) {
super(Collections.emptyList(),
(text, styleClasses) -> text.getStyleClass().addAll(styleClasses),
preserveStyle);
setStyleCodec(SuperCodec.upCast(SuperCodec.collectionListCodec(Codec.STRING_CODEC)));
}
/**
* Creates a text area with empty text content.
*/
public StyleClassedTextArea() {
this(true);
}
/**
* Convenient method to assign a single style class.
*/
public void setStyleClass(int from, int to, String styleClass) {
List styleClasses = new ArrayList<>(1);
styleClasses.add(styleClass);
setStyle(from, to, styleClasses);
}
}