Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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+" );
Expand Down Expand Up @@ -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);
}
});
}

/*
Expand Down Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down