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

dragging out of the window and back again messes up the cursor

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      javafx-sdk-16
      jdk 15.0.2
      Fails: macOS 11.5.1
      Succeeds: Windows 11

      A DESCRIPTION OF THE PROBLEM :
      - Consider a Stage with a Scene with a root Pane.
      - The pane’s cursorProperty depends on whether the mouse button is down.
      - The cursor in effect during a drag should stay the same when the user drags the cursor out of the window and then back in again.
      - If the mouse button is released while outside the window, setting the cursor to the not-pressed state should succeed.

      This works on Window 11 and fails on macOS.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the source code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Cursor stays the same as the cursor is dragged out of the window and back into the window.
      If the mouse button is released while outside the window, setting the cursor to the not-pressed state succeeds.
      ACTUAL -
      Cursor changes to <–> as the cursor is dragged out of the window and stays as <–> as the cursor is dragged back into the window.

      ---------- BEGIN SOURCE ----------
      package shop.examples;

      import javafx.application.Application;
      import javafx.beans.Observable;
      import javafx.scene.Cursor;
      import javafx.scene.Scene;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.Pane;
      import javafx.stage.Stage;


      public class ChangingCursor extends Application {

        Pane root;

        @Override
        public void start(Stage stage) {
          root = new Pane();
          root.setOnMousePressed (this::onMousePressed );
          root.setOnMouseReleased(this::onMouseReleased);
          root.setOnMouseEntered (this::onMouseEntered );
          root.setOnMouseExited (this::onMouseExited );
          root.cursorProperty().addListener(this::changedCursor);
          stage.setScene(new Scene(root, 300, 200));
          stage.show();
        }

        void onMousePressed (MouseEvent e) {
          System.out.println("pressed" ); root.setCursor(Cursor.CROSSHAIR);
        }
        void onMouseReleased(MouseEvent e) {
          System.out.println("released"); root.setCursor(Cursor.DEFAULT );
        }
        void onMouseEntered (MouseEvent e) {
          System.out.println("entered" ); root.setCursor(Cursor.HAND );
        }
        void onMouseExited (MouseEvent e) {
          System.out.println("exited" );
       // root.setCursor(Cursor.CLOSED_HAND); // has no effect
        }

        private void changedCursor(Observable ob, Cursor o, Cursor n) {
          System.out.println("changedCursor " + o + " " + n);
        }

        public static void main(String[] args) { launch(args); }
      }
      /*
        entered
        changedCursor null HAND
        exited
        // stays HAND
        entered
        // stays HAND
        pressed
        changedCursor HAND CROSSHAIR
        released
        changedCursor CROSSHAIR DEFAULT
        pressed
        changedCursor DEFAULT CROSSHAIR
        exited
        // cursor changed to <–>, with no change event
        released
        changedCursor CROSSHAIR DEFAULT <–– wrong; was <–> and stayed <–>
        entered
        changedCursor DEFAULT HAND <–– wrong; was <–>
        pressed
        changedCursor HAND CROSSHAIR
        exited
        // cursor changed to <–>, with no change event
        entered
        changedCursor CROSSHAIR HAND <–– wrong; was <–> and stayed <–>
        released
        changedCursor HAND DEFAULT <–– wrong; was <–> and stayed <–>
        // Here if you move the cursor,
        // it does change to DEFAULT, with no change event.
      */

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Attempts to change the cursor from <–> to what it should be have no effect.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: