All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fxmisc.richtext.StyleClassedTextArea Maven / Gradle / Ivy

There is a newer version: 0.11.3
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy