如何允许将MouseEvents调度到禁用的节点? [英] How to allow MouseEvents to be dispatched to disabled Nodes?

查看:101
本文介绍了如何允许将MouseEvents调度到禁用的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在fx中,不会将mouseEvents调度到禁用的节点,最后是一个简单的演示行为的示例.

In fx, mouseEvents aren't dispatched to disabled nodes, at the end is a quick example demonstrating the behaviour.

对于像我这样的Swinger来说,这有点令人惊讶:在我的土地上,事件已经交付,目标(ui-delegate)的任务是决定是否应对事件进行处理.实际上,最近的IMO(完全有效)已指出了这一点-在禁用组件上显示工具提示的用例

For a Swinger like me, that's a bit surprising: in my land, events are delivered and it's the task of the target (ui-delegate) to decide whether or not the event should be handled. Actually was pointed to this by a recent - perfectly valid, IMO - use-case of showing a tooltip over a disabled component

从技术上讲,似乎在Node的impl方法之一中中断了分派:

Technically, the dispatch seems to be cut off in one of Node's impl methods:

/**
 * Finds a top-most child node that intersects the given ray.
 *
 * The result argument is used for storing the picking result.
 */
@Deprecated
public final void impl_pickNode(PickRay pickRay, PickResultChooser result) {

    // In some conditions we can omit picking this node or subgraph
    if (!isVisible() || isDisable() || isMouseTransparent()) {
        return;
    }

似乎在匹配检测过程中被调用.如果是这样的话,那将是真正的肠子深处,而没有太多调整的机会.

which seems to be called during the hit detection process. If so, it would be really deep down in the bowels without much of chance to tweak.

问题:

  • 我的代码有任何问题(很容易错过明显的事情;-)
  • 以上确实是潜在原因吗?
  • 是否有任何可配置的选项来强制分派?如果可以,怎么办?
  • 行为规范在哪里?环顾了教程/api文档,但找不到任何东西.

代码示例:

package fx.control;

import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**
 * @author Jeanette Winzenburg, Berlin
 */
public class MouseEventDisabled extends Application {

    private Parent getContent() {

        Pane parent = new Pane();
        Rectangle r = new Rectangle(100, 100, 200, 200);
        r.addEventHandler(MouseEvent.ANY, event -> System.out.println(event));        
        CheckBox button = new CheckBox("rectangle disabled");
        r.disableProperty().bind(button.selectedProperty());
        parent.getChildren().addAll(r, button);
        return parent;
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = getContent();
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

推荐答案

公共最终ReadOnlyBooleanProperty disabledProperty

指示是否禁用了该节点.如果在场景图中其自身或其祖先之一的disable设置为true,则Node将被禁用. 禁用的节点应以不同的方式呈现自己,以向用户指示其禁用状态.这种禁用的渲染取决于Node的实现.默认情况下,javafx.scene.shape中包含的形状类不会实现此类渲染,因此,使用形状来处理输入的应用程序必须自己实现适当的禁用渲染.但是,在javafx.scene.control中定义的用户界面控件将实现禁用敏感的呈现.

Indicates whether or not this Node is disabled. A Node will become disabled if disable is set to true on either itself or one of its ancestors in the scene graph. A disabled Node should render itself differently to indicate its disabled state to the user. Such disabled rendering is dependent on the implementation of the Node. The shape classes contained in javafx.scene.shape do not implement such rendering by default, therefore applications using shapes for handling input must implement appropriate disabled rendering themselves. The user-interface controls defined in javafx.scene.control will implement disabled-sensitive rendering, however.

禁用的节点未收到鼠标或关键事件.

默认值: 错误的 也可以看看: isDisabled(),setDisabled(boolean)

Default value: false See Also: isDisabled(), setDisabled(boolean)

这篇关于如何允许将MouseEvents调度到禁用的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆