Consuming Events with EventFilters

孤者浪人 提交于 2019-12-02 04:14:59

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!