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

JavaFX touch pressed event does not cause button's pressed property to become true

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.16299.64]

      A DESCRIPTION OF THE PROBLEM :
      The pressed property of a Button should be true when the button is being pressed. When pressed with the mouse, the property does indeed become true in response to the "mouse pressed" event. When pressed with a finger on a touch screen, however, the pressed property does not become true in response to the "touch pressed" event.

      If you move your finger slightly after pressing down on the button, the pressed property will become true. This is not the case with the mouse: you do not need to drag the mouse on the button to make the pressed property become true.

      This seems like a bug, in that the pressed property should be set to true immediately after a "touch pressed" event.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program. It binds the button's background to the pressed property. Normally the button will be light blue, and when the pressed property is true then the background is red.

      The button should go red when pressed, but on a Windows touch screen (e.g. Surface tablet) it only goes red if you touch the button and then move your finger. The bug is that it does not go red if you touch the button and keep your finger stationary. When you press the button with the mouse it goes red immediately, without moving the mouse.

      Note that on the console output a "touch pressed" event does occur when you touch the buttton with your finger, but this does not cause the button's pressed property to become true. When you press the button using the mouse, however, the "mouse pressed" event does seem sufficient to set the pressed property to true.

      Tested with Java 8u151 on Surface Pro 3 tablet running Windows 10 (version 1709)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The button should go red when you press on it with your finger on a touch screen, without moving your finger after pressing.
      ACTUAL -
      The button does not go red.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.binding.Bindings;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.StackPane;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;

      public class TouchEventProblem extends Application {

          // The button should go red when pressed, but on a Windows touch screen
          // (e.g. Surface tablet) it only goes red if you touch the button and
          // then move your finger. The bug is that it does not go red if you
          // touch the button and keep your finger stationary. When you press the
          // button with the mouse it goes red immediately, without moving the mouse.

          // Note that on the console output a "touch pressed" event does occur
          // when you touch the buttton with your finger, but this does not cause the
          // button's pressed property to become true. When you press the button
          // using the mouse, however, the "mouse pressed" event does seem sufficient
          // to set the pressed property to true.

          // Tested with Java 8u151 on Surface Pro 3 tablet running Windows 10 (version 1709)
              
          @Override
          public void start(Stage primaryStage) {
              // create button
              Button button = new Button();
              button.setPrefSize(200, 200);

              // create two backgrounds
              Background normalBackground = new Background(new BackgroundFill(Color.LIGHTBLUE, null, null));
              Background pressedBackground = new Background(new BackgroundFill(Color.RED, null, null));

              // bind backgrounds to pressed property
              button.backgroundProperty().bind(Bindings
                      .when(button.pressedProperty())
                      .then(pressedBackground)
                      .otherwise(normalBackground)
              );
                     
              // print out button's pressed property status
              button.pressedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                  System.out.println(System.currentTimeMillis() + ": PressedProperty = " + newValue);
              });
              
              // print out touch events
              button.setOnTouchPressed(e -> System.out.println(System.currentTimeMillis() + ": Touch Pressed event"));
              button.setOnTouchReleased(e -> System.out.println(System.currentTimeMillis() + ": Touch Released event"));

              // print out mouse events
              button.setOnMousePressed(e -> System.out.println(System.currentTimeMillis() + ": Mouse Pressed event"));
              button.setOnMouseReleased(e -> System.out.println(System.currentTimeMillis() + ": Mouse Released event"));
                      
              // create stage
              StackPane root = new StackPane();
              root.getChildren().add(button);
              Scene scene = new Scene(root, 300, 250);
              primaryStage.setTitle("TouchEventProblem");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

      }

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

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: