Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX8:Treeview,获取鼠标单击图标或文本_Javafx_Treeview_Icons_Label_Mouseevent - Fatal编程技术网

JavaFX8:Treeview,获取鼠标单击图标或文本

JavaFX8:Treeview,获取鼠标单击图标或文本,javafx,treeview,icons,label,mouseevent,Javafx,Treeview,Icons,Label,Mouseevent,根据用户在图标或文本标签上的单击,我可以从TreeView项目中获得不同的鼠标单击事件吗?图标不是树的折叠图像。根据我更改了TreeMouseEventDispatcher的构造函数: class TreeMouseEventDispatcher implements EventDispatcher { private final EventDispatcher originalDispatcher; private final TreeCell<?> cell;

根据用户在图标或文本标签上的单击,我可以从TreeView项目中获得不同的鼠标单击事件吗?图标不是树的折叠图像。

根据我更改了TreeMouseEventDispatcher的构造函数:

class TreeMouseEventDispatcher implements EventDispatcher {
    private final EventDispatcher originalDispatcher;
    private final TreeCell<?> cell;

    public TreeMouseEventDispatcher(EventDispatcher originalDispatcher, TreeCell<?> cell) {
      this.originalDispatcher = originalDispatcher;
      this.cell = cell;
    }

    private boolean isMouseEventOnGraphic(Node icon, Point2D coord) {
        if (icon == null) {
           return false;
        }
        return icon.localToScene(icon.getBoundsInLocal()).contains(coord);
    }

    @Override
    public Event dispatchEvent(Event event, EventDispatchChain tail) {
        if (event instanceof MouseEvent) {
           MouseEvent mouseEvent = (MouseEvent) event;
           if (mouseEvent.getButton() == MouseButton.PRIMARY
               && mouseEvent.getClickCount() >= 2) {

             if (!mouseEvent.isConsumed()) {
                if (isMouseEventOnGraphic(cell.getGraphic(), new Point2D(mouseEvent.getSceneX(), mouseEvent.getSceneY()))) {
                   // action for double click on graphic
                } else {
                   // action for double click on all other elements of
                   // the TreeCell (like text, text gap, disclosure node)
                }
             }
             event.consume();
           }
        }
        return originalDispatcher.dispatchEvent(event, tail);
    }
}
根据,我已更改TreeMouseEventDispatcher的构造函数:

class TreeMouseEventDispatcher implements EventDispatcher {
    private final EventDispatcher originalDispatcher;
    private final TreeCell<?> cell;

    public TreeMouseEventDispatcher(EventDispatcher originalDispatcher, TreeCell<?> cell) {
      this.originalDispatcher = originalDispatcher;
      this.cell = cell;
    }

    private boolean isMouseEventOnGraphic(Node icon, Point2D coord) {
        if (icon == null) {
           return false;
        }
        return icon.localToScene(icon.getBoundsInLocal()).contains(coord);
    }

    @Override
    public Event dispatchEvent(Event event, EventDispatchChain tail) {
        if (event instanceof MouseEvent) {
           MouseEvent mouseEvent = (MouseEvent) event;
           if (mouseEvent.getButton() == MouseButton.PRIMARY
               && mouseEvent.getClickCount() >= 2) {

             if (!mouseEvent.isConsumed()) {
                if (isMouseEventOnGraphic(cell.getGraphic(), new Point2D(mouseEvent.getSceneX(), mouseEvent.getSceneY()))) {
                   // action for double click on graphic
                } else {
                   // action for double click on all other elements of
                   // the TreeCell (like text, text gap, disclosure node)
                }
             }
             event.consume();
           }
        }
        return originalDispatcher.dispatchEvent(event, tail);
    }
}