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

JavaFX doesn't display the proper hand cursor

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 20.04.6 LTS.
      Openjdk version "22.0.1" 2024-04-16
      JavaFX 25-ea+20

      A DESCRIPTION OF THE PROBLEM :
      JavaFX does not display the proper hand cursor even though the cursor icons exist in the OS and the current theme.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided code in Ubuntu. Try to perform drag and drop. You will see , the cursor changes to a closed hand. However, when you move the mouse over the other three VBoxes, the cursor remains the same (closed hand is now shown)

      ACTUAL -
      <External link>

      ---------- BEGIN SOURCE ----------
      public class CursorTest extends Application {

          @Override
          public void start(Stage primaryStage) {

              VBox dndBox = new VBox(new Label("DragAndDrop"));
              dndBox.setPrefSize(100, 100);
              dndBox.setStyle("-fx-background-color: yellow");
              dndBox.setOnDragDetected(event -> {
                  Dragboard db = dndBox.startDragAndDrop(TransferMode.COPY);
                  ClipboardContent content = new ClipboardContent();
                  content.putString("test");
                  db.setContent(content);
                  event.consume();
              });

              VBox handBox = createColoredBox(Color.LIGHTBLUE, Cursor.HAND);
              VBox closedHandBox = createColoredBox(Color.LIGHTCORAL, Cursor.CLOSED_HAND);
              VBox openHandBox = createColoredBox(Color.LIGHTGREEN, Cursor.OPEN_HAND);

              VBox root = new VBox(10, dndBox, handBox, closedHandBox, openHandBox);

              Scene scene = new Scene(root, 320, 350);
              primaryStage.setTitle("Cursor Test");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          private VBox createColoredBox(Color color, Cursor cursor) {
              VBox box = new VBox(new Label(cursor.toString()));
              box.setPrefSize(100, 100);
              box.setStyle(String.format("-fx-background-color: #%s;", color.toString().substring(2, 8)));
              box.setCursor(cursor);
              return box;
          }

          public static void main(String[] args) {
              launch(args);
          }
      }
      ---------- END SOURCE ----------

        1. recording_submitter.gif
          92 kB
          Anupam Dev
        2. Recording_Ubuntu24.mp4
          18.77 MB
          Anupam Dev

            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: