【问题标题】:How to allow MouseEvents to be dispatched to disabled Nodes?如何允许将 MouseEvents 分派到禁用的节点?
【发布时间】:2014-06-12 11:05:04
【问题描述】:

在 fx 中,mouseEvents 不会分派到禁用的节点,最后是一个演示该行为的快速示例。

对于像我这样的 Swinger 来说,这有点令人惊讶:在我的土地上,事件被传递,并且目标(ui-delegate)的任务是决定是否应该处理事件。实际上是由最近的 - 完全有效的 IMO - use-case of showing a tooltip over a disabled component

指出的

从技术上讲,调度似乎在 Node 的 impl 方法之一中被切断:

/**
 * 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;
    }

这似乎在命中检测过程中被调用。如果是这样,那它就真的是根深蒂固了,没有太多调整的机会。

问题:

  • 我的代码有任何问题(很容易漏掉一些明显的东西 ;-)
  • 以上真的是根本原因吗?
  • 是否有任何可配置的选项来强制调度?如果是这样,怎么做?
  • 行为规范在哪里?环顾了 tutorials/api doc,但找不到任何东西。

代码示例:

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();
    }
}

【问题讨论】:

    标签: java swing mouseevent javafx-8


    【解决方案1】:

    public final ReadOnlyBooleanProperty disabledProperty

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

    A disabled Node does not receive mouse or key events.

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

    【讨论】:

    • +1 表示问题,难以覆盖 API 中的方法,我对此表示怀疑
    猜你喜欢
    • 1970-01-01
    • 2019-08-05
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多