【发布时间】: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