JDK-8087573 : [Glass, win32] Controls get refocused on window restore before they know their position (wrong Node.localToScreen(Point2D) behavior)
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: 8u20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-03-03
  • Updated: 2018-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Blocks :  
Relates :  
Description
I don't know whether this is a bug or a feature. But if it's a feature, it's pretty bad one.
In my application, I display a Popup window with features complementing a TextField (imagine a bunch of Toggles denoting the field's content type). The popup visibility is bound to the text field's focus property so it stays on screen only when user needs it. It also keeps track of the field's position changes so it stays well positioned each time user moves the application window.
Whenever the text field gains focus, the field's on-screen position is required in order to place the popup correctly. I use the field's Node.localToScreen(Point2D) method for this.

If I have the field focused and minimize the application window, the field losts its focus and the popup closes. 

Now -- If I decide to restore the window again, the field regains its focus but its localToScreen() method returns negative numbers somewhere around -31000 which makes the popup reappear somewhere in the outer space.
Comments
Maybe, but it won't be enough. There's another related issue -- same as in my application, a popup window is displayed only when a text field is focused. The focus is lost when the user minimizes the application using a button on its title bar, but lost and regained if he minimizes it by clicking on its icon on taskbar. Thus the popup window stays visible. I'll create two tickets then. EDIT: DTL-6679, RT-36536
04-04-2014

Jan, can you please enter a bug report against SB and link back to this issue? Thanks.
04-04-2014

Perhaps SceneBuilder should work around it in a similar fashion.
04-04-2014

This problem appears in the current version of Scene Builder as well (Style auto-complete popup window).
04-04-2014

That looks dirty, indeed, but it works. This is good. I suggest to add some limit on the number of recursive calls though, just to make sure you don't hang up your process. Also, thank you for testing on Linux. This seems to be a Windows-specific issue then. We'll investigate it.
04-03-2014

Ok I tried the workaround and to achieve consistent results, I had to do something very dirty :-) But it works fine now. public void showPositioned() { final Point2D p = computePosition(); show(owner, p.getX(), p.getY()); /* RT-36089 workaround */ Platform.runLater(new Runnable() { @Override public void run() { Point2D p; p = computePosition(); updatePosition(p); if ((p.getX() < 0.0) && (p.getY() < 0.0) && isAutoFix() && isVisible()) // This can't be true if everything works well { Platform.runLater(this); // Try again later } } }); // updatePosition(); }
04-03-2014

Thanks for the test case. A workaround might be to runLater() from your focus event listener and perform the localToScreen() call from the runLater() runnable. This should postpone the request so that it's performed when the correct position of the window is already known. BTW, have you tried other platforms (Mac, Linux)? Is the behavior any different there?
04-03-2014

Any idea how to get around this (since it seems from you comment it's not going to be fixed, at least not soon)? If I leave the popup opened, then it reappears where it should, but I can't do it like that. I'd have to detect minimalization of a window from the inside of a control and I guess there's no clean way to do that.
04-03-2014

Code to reproduce: import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.stage.Stage; public class Test7 extends Application { public static void main(final String[] args) { launch(args); } @Override public void start(final Stage primaryStage) throws Exception { final TextField field = new TextField(); field.setPrefColumnCount(30); field.setEditable(false); field.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(final ObservableValue<? extends Boolean> observable, final Boolean oldValue, final Boolean newValue) { if (newValue) { field.setText(field.localToScreen(0.0, 0.0).toString()); } } }); primaryStage.setScene(new Scene(field)); primaryStage.show(); field.requestFocus(); } } 1. Run the application. There's a focused text field with its on-screen coordinates in it. These coordinates update each time the field gains focus. 2. Minimize and restore the application window. 3. The coordinates inside the field are now incorrect.
04-03-2014

Just tried it under Ubuntu 13.10 and it works fine there. Thank you for the workaround. I'll give it a try.
04-03-2014

I'm betting this is the classic Windows behaviour where a window that is minimized reports it's position in the operating system at a strange negative location. We'll need test code to prove it though. If it turns out to be what I think it is, we'll need to decide what (if anything) we should do about it. First off, it might be an FX bug and the application code could be correct (yes, when the window is minimized, it puts the popup in a strange place but when the window is restored, the popup should go back to a good place ��� maybe). In any case,. we can't proceed without test code. Please reopen with a small sample and some steps that show the problem. https://wiki.openjdk.java.net/display/OpenJFX/Submitting+a+Bug+Report
03-03-2014