Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8166414

Scene returns incorrect coordinates

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8, 9
    • Fix Version/s: 9
    • Component/s: javafx
    • Labels:
    • Environment:

      9, b136

      Description

      Secondary scene returns incorrect coordinates.
      The sample below returns something like

      x: 974.5
      y: 369.33334362506866
      x: 65.0
      y: 24.0

      At the same an actual window position is correct.

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.stage.Modality;
      import javafx.stage.Stage;
      import javafx.stage.WindowEvent;

      public class App extends Application {
          public static void main(String[] args) {
              launch(args);
          }

          public void start(Stage primaryStage) {

              class MyDialog extends Stage {

                  public MyDialog(Stage parent) {
      // initOwner(parent);
      // initModality(Modality.WINDOW_MODAL);
                      setScene(new Scene(new Label("Label")));
                      sizeToScene();
                  }
              }

              Button button = new Button("Show Dialog");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      final Stage dlg = new MyDialog(primaryStage);
                      dlg.xProperty().addListener(new ChangeListener<Number>() {
                          @Override
                          public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                              System.out.println("x: " + newValue);
                          }
                      });
                      dlg.yProperty().addListener(new ChangeListener<Number>() {
                          @Override
                          public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                              System.out.println("y: " + newValue);
                          }
                      });
                      dlg.showAndWait();
                  }
              });

              primaryStage.setScene(new Scene(button));
              primaryStage.show();
          }

      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ssadetsky Semyon Sadetsky (Inactive)
                Reporter:
                ogb Oleg Barbashov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: