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

[Events] BorderPane will not consume the event and it may be passed to contained control

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 8u5
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Environment:

      Mac OS X 10.9.2, Java 8u5.

      Description

      Sometimes on Mac, BorderPane will not consume the event, thus it will be passed to an inclosed control, a button for example. To reproduce:

      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class App extends Application
      {
          @Override
          public void start(Stage stage) throws Exception
          {
              Button b = new Button("Button");
              b.setOnKeyPressed(new EventHandler<KeyEvent>(){
                  @Override
                  public void handle(KeyEvent event) {
                      if (event.isShortcutDown()) {
                          System.out.println(event.getCode() + ", " + event.getCharacter() + " pressed in Button, shortcut: " + event.isShortcutDown());
                          event.consume();
                      }
                  }
              });

              final BorderPane p = new BorderPane();
              p.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                  @Override
                  public void handle(KeyEvent event)
                  {
                      if (event.isShortcutDown()) {
                          System.out.println(event.getCode() + ", " + event.getCharacter() + " pressed in BorderPane, shortcut: " + event.isShortcutDown());
                          event.consume();
                      }
                  }
              });
              p.setCenter(b);

              Scene s = new Scene(new VBox());
              ((VBox)s.getRoot()).getChildren().add(p);
              stage.setScene(s);
              stage.show();
          }
      }

      The output will be from the both controllers.

      P.S. I have tried to change the 'setOnKeyPressed' to 'setOnKeyTyped' and/or change 'keyEvent.KEY_PRESSED' to 'keyEvent.KEY_TYPED', but has the same results.

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: