Skip to content

Commit 8502e96

Browse files
authored
Fix for SceneBuilder compatibility (#1112)
1 parent 5ac2039 commit 8502e96

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.fxmisc.richtext.model.EditableStyledDocument;
1010

1111
import javafx.application.Application;
12+
import javafx.application.Platform;
1213
import javafx.beans.NamedArg;
1314
import javafx.beans.binding.Bindings;
1415
import 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

Comments
 (0)