Consuming Events with EventFilters

前端 未结 1 977
走了就别回头了
走了就别回头了 2021-01-26 19:57

First, can anyone explain to me, why my MouseEvent gets consumed no matter which Alert-Option I choose? I guess it has something to do with calling an

相关标签:
1条回答
  • 2021-01-26 20:32

    I debugged it and my guess is that it's a bug, you should file a bug report. The event isn't consumed as long as you remain in the EventFilter. Sometimes after that code was processed, the event appears to be consumed in the bubbling event. That's probably a side-effect of the nested eventing in the Alert class.

    You can solve that problem easily by always consuming the event and setting the checkbox manually, i. e.

      if ( alert.showAndWait().get().equals( ButtonType.OK ) )
      {
        System.out.println( "Yes, consume Event" );
        event.consume();
      }
      else
      {
        System.out.println( "No, do NOT consume Event" );
        //<-- Why is the Event consumed anyway? onAction won´t be called.
    
        // always consume the event
        event.consume();
    
        // trigger the change manually
        checkBox.setSelected(!checkBox.isSelected());
    
      }
    

    However, you got another problem there, e. g. if a user triggers the checkbox selection event by keyboard (space bar). But you explicitly caught the mouse event, so I leave it at that (hint: you could e. g. revert the selection in the onAction event).

    Tried it on Win7 x64 with Java 8u66 and Java 8u74.

    0 讨论(0)
提交回复
热议问题