kle*_*tra 6 java swing mouseevent javafx-8
在fx中,mouseEvents不会被分派到禁用的节点,最后是一个演示行为的快速示例.
对于像我这样的Swinger,这有点令人惊讶:在我的土地上,事件被传递,目标(ui-delegate)的任务是决定是否应该处理事件.实际上是由最近的一个 - 完全有效的IMO 用例 - 在禁用的组件上显示工具提示而指出的
从技术上讲,在一个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;
}
Run Code Online (Sandbox Code Playgroud)
这似乎是在命中检测过程中调用的.如果是这样的话,那么在没有太大机会进行调整的情况下,它会非常深入.
问题:
代码示例:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
publicfinalReadOnlyBooleanPropertydisabledProperty
指示该节点是否被禁用。如果节点本身或其在场景图中的祖先之一的禁用设置为 true,则该节点将被禁用。禁用的节点应该以不同的方式呈现自身,以向用户指示其禁用状态。这种禁用渲染取决于 Node.js 的实现。javafx.scene.shape 中包含的形状类默认不实现此类渲染,因此使用形状处理输入的应用程序必须自己实现适当的禁用渲染。然而,javafx.scene.control 中定义的用户界面控件将实现禁用敏感渲染。
默认值: false 另请参阅: isDisabled()、setDisabled(boolean)
| 归档时间: |
|
| 查看次数: |
678 次 |
| 最近记录: |