diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java index 7c82295f0..0232d5a8f 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java @@ -24,6 +24,16 @@ import javafx.scene.layout.Pane; import javafx.scene.text.TextFlow; +/** + * A text field whose segment generic has been specified to be a {@link String}. How the text + * will be styled is not yet specified in this class, but use {@link StyleClassedTextField} for a style class + * approach to styling the text and {@link InlineCssTextField} for an inline css approach to styling the text. + * + * @param <PS> type of paragraph style + * @param <S> type of style that can be applied to text. + * + * @author Jurgen + */ public class StyledTextField<PS, S> extends StyledTextArea { private final Pattern VERTICAL_WHITESPACE = Pattern.compile( "\\v+" ); @@ -82,6 +92,14 @@ else if ( ! focused && was ) { } selectAll = true; }); + + super.setWrapText( false ); + wrapTextProperty().addListener( (ob,ov,wrap) -> { + if ( wrap ) { // veto any changes + wrapTextProperty().unbind(); + super.setWrapText(false); + } + }); } /* @@ -155,4 +173,9 @@ public void replaceText( int start, int end, String text ) { super.replaceText( start, end, VERTICAL_WHITESPACE.matcher( text ).replaceAll( " " ) ); } + + /** This is a <b>no op</b> for text fields and therefore marked as <i>deprecated</i>. */ + @Override @Deprecated public void setWrapText( boolean value ) {} + /** This <u>always</u> returns <b>false</b> for styled text fields. */ + @Override public boolean isWrapText() { return false; } } diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/package-info.java b/richtextfx/src/main/java/org/fxmisc/richtext/package-info.java index 6a80240c2..ec6e38348 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/package-info.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/package-info.java @@ -10,6 +10,11 @@ * {@link org.fxmisc.richtext.StyleClassedTextArea} and {@link org.fxmisc.richtext.InlineCssTextArea}. * For those looking to use a base for a code editor, see {@link org.fxmisc.richtext.CodeArea}. * </p> + * <p> + * For text fields there is {@link org.fxmisc.richtext.StyledTextField} using {@link java.lang.String}-only segments, + * and styling them are also already supported in the two most common ways via + * {@link org.fxmisc.richtext.StyleClassedTextField} and {@link org.fxmisc.richtext.InlineCssTextField}. + * </p> * * @see org.fxmisc.richtext.model.EditableStyledDocument * @see org.fxmisc.richtext.model.TwoDimensional