Skip to content

Commit ef547eb

Browse files
authored
Prevent wrap text from being set true for text fields. (#895)
* Prevent wrap text from being set true for text fields. * Updated package info for styled text fields.
1 parent 2f8a72b commit ef547eb

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
import javafx.scene.layout.Pane;
2525
import javafx.scene.text.TextFlow;
2626

27+
/**
28+
* A text field whose segment generic has been specified to be a {@link String}. How the text
29+
* will be styled is not yet specified in this class, but use {@link StyleClassedTextField} for a style class
30+
* approach to styling the text and {@link InlineCssTextField} for an inline css approach to styling the text.
31+
*
32+
* @param <PS> type of paragraph style
33+
* @param <S> type of style that can be applied to text.
34+
*
35+
* @author Jurgen
36+
*/
2737
public class StyledTextField<PS, S> extends StyledTextArea
2838
{
2939
private final Pattern VERTICAL_WHITESPACE = Pattern.compile( "\\v+" );
@@ -82,6 +92,14 @@ else if ( ! focused && was ) {
8292
}
8393
selectAll = true;
8494
});
95+
96+
super.setWrapText( false );
97+
wrapTextProperty().addListener( (ob,ov,wrap) -> {
98+
if ( wrap ) { // veto any changes
99+
wrapTextProperty().unbind();
100+
super.setWrapText(false);
101+
}
102+
});
85103
}
86104

87105
/*
@@ -155,4 +173,9 @@ public void replaceText( int start, int end, String text )
155173
{
156174
super.replaceText( start, end, VERTICAL_WHITESPACE.matcher( text ).replaceAll( " " ) );
157175
}
176+
177+
/** This is a <b>no op</b> for text fields and therefore marked as <i>deprecated</i>. */
178+
@Override @Deprecated public void setWrapText( boolean value ) {}
179+
/** This <u>always</u> returns <b>false</b> for styled text fields. */
180+
@Override public boolean isWrapText() { return false; }
158181
}

richtextfx/src/main/java/org/fxmisc/richtext/package-info.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
* {@link org.fxmisc.richtext.StyleClassedTextArea} and {@link org.fxmisc.richtext.InlineCssTextArea}.
1111
* For those looking to use a base for a code editor, see {@link org.fxmisc.richtext.CodeArea}.
1212
* </p>
13+
* <p>
14+
* For text fields there is {@link org.fxmisc.richtext.StyledTextField} using {@link java.lang.String}-only segments,
15+
* and styling them are also already supported in the two most common ways via
16+
* {@link org.fxmisc.richtext.StyleClassedTextField} and {@link org.fxmisc.richtext.InlineCssTextField}.
17+
* </p>
1318
*
1419
* @see org.fxmisc.richtext.model.EditableStyledDocument
1520
* @see org.fxmisc.richtext.model.TwoDimensional

0 commit comments

Comments
 (0)