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

Not all mouse click events on Rectangle are caught

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: fx2.0
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Environment:

      JavaFX 2.0 beta b28 + JDK1.6.0_25 + WinXP SP3

      Description

      The mouse click events on Rectangle are not all caught - the system/runtime seems not to be sensitive/quick
      enough to catch such events. On the other hand, for mouse click event on Button, the system/runtime seems to
      be sensitive/quick enough to catch every event.

      Below codes used to re-produce...

      1. Quickly click on one rectangle, then, another, then, another,,,
         You will see NOT all click-event generates output messsage
      2. Quickly click on one button, then, another, then, another,,,
         You will see all click-event generates output messsage

      --- Code for re-producing ---
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.HBox;
      import javafx.scene.paint.Color;
      import javafx.scene.paint.Paint;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;

      /**
       *
       * @author lianqi.li
       */
      public class EventIssue extends Application {
          @Override public void start(Stage stage) {
              final Group root = new Group();
              final Scene scene = new Scene(root, 400, 300);
              
              Rectangle[] rects = {new Rectangle(50, 50, Color.RED), new Rectangle(50, 50, Color.YELLOW), new Rectangle(50, 50, Color.BLUE), new Rectangle(50, 50, Color.GREEN)};
              for (int i = 0; i < rects.length; i++) {
                  final Paint color = rects[i].getFill();
                  final int n = i;
                  rects[i].setOnMouseClicked(new EventHandler<MouseEvent>() {
                      @Override
                      public void handle(MouseEvent event) {
                          System.out.println("Clicked on #" + n + " - " + color);
                      }
                  });
              }

              Button[] buttons = {new Button("Button1"), new Button("Button2"), new Button("Button3"), new Button("Button4")};
              for (int i = 0; i < buttons.length; i++) {
                  final int n = i;
                  buttons[i].setOnAction(new EventHandler<ActionEvent>() {
                      @Override
                      public void handle(ActionEvent event) {
                          System.out.println("Clicked on button" + n);
                      }
                  });
              }

              HBox hBox1 = new HBox(10);
              hBox1.getChildren().addAll(rects);

              HBox hBox2 = new HBox(10);
              hBox2.getChildren().addAll(buttons);

              hBox1.setTranslateX(50);
              hBox1.setTranslateY(50);
              hBox2.setTranslateX(50);
              hBox2.setTranslateY(250);

              root.getChildren().addAll(hBox1, hBox2);
              
              stage.setScene(scene);
              stage.setVisible(true);
          }

          public static void main(String[] args) {
              Application.launch(EventIssue.class, args);
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              lnerad Ľubomír Nerád
              Reporter:
              lianqli Lianqi Li (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: