File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
modules/javafx.controls/src
main/java/javafx/scene/control/skin
test/java/test/javafx/scene/control/skin Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -334,7 +334,10 @@ protected boolean computeValue() {
334334 control .setInputMethodRequests (new ExtendedInputMethodRequests () {
335335 @ Override public Point2D getTextLocation (int offset ) {
336336 Scene scene = getSkinnable ().getScene ();
337- Window window = scene .getWindow ();
337+ Window window = scene != null ? scene .getWindow () : null ;
338+ if (window == null ) {
339+ return new Point2D (0 , 0 );
340+ }
338341 // Don't use imstart here because it isn't initialized yet.
339342 Rectangle2D characterBounds = getCharacterBounds (control .getSelection ().getStart () + offset );
340343 Point2D p = getSkinnable ().localToScene (characterBounds .getMinX (), characterBounds .getMaxY ());
Original file line number Diff line number Diff line change 2626package test .javafx .scene .control .skin ;
2727
2828import java .util .concurrent .atomic .AtomicBoolean ;
29+ import javafx .geometry .Point2D ;
2930import javafx .scene .control .TextArea ;
3031import javafx .scene .control .TextField ;
3132import javafx .scene .control .PasswordField ;
3233import javafx .scene .control .skin .TextAreaSkin ;
3334import javafx .scene .control .skin .TextFieldSkin ;
3435import org .junit .Test ;
36+ import static org .junit .Assert .assertEquals ;
3537import static org .junit .Assert .assertFalse ;
3638import static org .junit .Assert .assertTrue ;
3739
@@ -92,6 +94,17 @@ public class TextInputControlSkinTest {
9294 passwordField .setText (null );
9395 }
9496
97+ @ Test public void noNullPointerIfTextInputNotInScene () {
98+ TextField textField = new TextField ();
99+ TextFieldSkin skin = new TextFieldSkin (textField );
100+ textField .setSkin (skin );
101+
102+ // Check that no NullPointerException is thrown if the TextField is not in scene
103+ // and that the default point is returned.
104+ Point2D point = textField .getInputMethodRequests ().getTextLocation (0 );
105+ assertEquals (new Point2D (0 , 0 ), point );
106+ }
107+
95108 public class FocusableTextField extends TextField {
96109 public void setFocus (boolean value ) {
97110 super .setFocused (value );
You can’t perform that action at this time.
0 commit comments