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

EventFilter aren't filtering events on the javafx.scene.Group

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 7u40, 7u45
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b91)
      Java HotSpot(TM) Client VM (build 25.0-b33, mixed mode, sharing)
      Windows 7 Home Edition

      JDK 8 32 bit version

      Description

      When EventFilters are applied to a parent node the developer has the opportunity to intercept and handle mouse events before the children respond. I created a simple test to hover over a group containing a Circle.

      When moving the mouse toward the bounding box of a parent inward containing a circle (corner area) the circle's opacity becomes 1. Meaning the mouse hasn't touch the circle yet and entering the parent first. The parent would handle the mouse enter and exit events. When using an HBox the test works as the mouse enters the corner area of the parent (HBox) the circle immediately turns to an opacity of 1. When using a javafx.scene.Group the mouse enters the parent area (corner) and doesn't respond until the mouse reaches the circle.

      Running the code below will show the correct behavior. Commenting out the line with the HBox statement and Un-commenting the Group statement will show the incorrect behavior.


      package sample;

      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Circle;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;
      import javafx.stage.StageStyle;

      public class Main2 extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception{

              Pane root = new Pane();

              //Group parent = new Group();
              HBox parent = new HBox();
              parent.setOpacity(.5);

              EventHandler<MouseEvent> mouseEntered = e -> ((Parent) e.getSource()).setOpacity(1);
              EventHandler<MouseEvent> mouseExit = e -> ((Parent) e.getSource()).setOpacity(.5);
              EventHandler<MouseEvent> mousePressed = e -> System.out.println(e);
              EventHandler<MouseEvent> mouseClicked = e -> System.out.println(e);

              parent.addEventFilter(MouseEvent.MOUSE_ENTERED, mouseEntered);
              parent.addEventFilter(MouseEvent.MOUSE_EXITED, mouseExit);
              parent.addEventFilter(MouseEvent.MOUSE_PRESSED, mousePressed);
              parent.addEventFilter(MouseEvent.MOUSE_CLICKED, mouseClicked);

              Circle c = new Circle();
              c.setStroke(Color.BLUE);
              c.setCenterX(100);
              c.setCenterY(100);
              c.setRadius(50);
              c.setStrokeWidth(10);
              parent.getChildren().add(c);
              root.getChildren().add(parent);
              primaryStage.setScene(new Scene(root, 300, 275, null));
              primaryStage.show();

          }


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

        Attachments

          Activity

            People

            • Assignee:
              psafrata Pavel Ĺ afrata
              Reporter:
              cdea Carl Dea
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: