99import org .fxmisc .richtext .model .EditableStyledDocument ;
1010
1111import javafx .application .Application ;
12+ import javafx .application .Platform ;
1213import javafx .beans .NamedArg ;
1314import javafx .beans .binding .Bindings ;
1415import javafx .beans .property .ObjectProperty ;
@@ -65,7 +66,7 @@ public abstract class StyledTextField<PS, S> extends StyledTextArea<PS, S>
6566
6667 private final static Pattern VERTICAL_WHITESPACE = Pattern .compile ( "\\ v+" );
6768 private final static String STYLE_SHEET ;
68- private final static double HEIGHT ;
69+ private static double HEIGHT = 24 ;
6970 static {
7071 List <CssMetaData <? extends Styleable , ?>> styleables = new ArrayList <>(GenericStyledArea .getClassCssMetaData ());
7172 styleables .add ( PROMPT_TEXT_FILL ); styleables .add ( TEXT_ALIGNMENT );
@@ -79,9 +80,13 @@ public abstract class StyledTextField<PS, S> extends StyledTextArea<PS, S>
7980
8081 // Ugly hack to get a TextFields default height :(
8182 // as it differs between Caspian, Modena, etc.
82- TextField tf = new TextField ( "GetHeight" );
83- new Scene (tf ).snapshot ( null );
84- HEIGHT = tf .getHeight ();
83+ Runnable snapshot = () -> {
84+ TextField tf = new TextField ( "GetHeight" );
85+ new Scene (tf ).snapshot ( null );
86+ HEIGHT = tf .getHeight ();
87+ };
88+ if ( Platform .isFxApplicationThread () ) snapshot .run ();
89+ else Platform .runLater ( snapshot );
8590 }
8691
8792 private boolean selectAll = true ;
0 commit comments