【发布时间】:2010-06-08 19:58:47
【问题描述】:
当我关闭它们时,我花了一段时间才意识到鼠标事件通过我的阻塞对话框发生了什么,但我终于弄清楚了原因。我仍然不知道有什么好的方法来解决它。
我有一个带有关闭按钮的自定义对话框(阻止鼠标)。当我单击关闭按钮时,我从场景中删除了对话框,但 JavaFx 仍在处理 MouseEvent,现在它发现取消按钮所在的屏幕后面没有任何东西阻塞,因此该组件接收到 MouseEvent。当我看到他们按下取消并删除对话框时,如何让 mouseEvent 停止处理?或者,有没有办法让对话框在处理完 MouseEvent 之后才会删除?
问题的示例代码:
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.input.MouseEvent;
import javafx.scene.control.Button;
var theScene:Scene;
var btn:Button;
Stage {
title: "Application title"
scene: theScene= Scene {
width: 500
height: 200
content: [
Rectangle{
width: bind theScene.width
height: bind theScene.height
onMouseClicked: function(e:MouseEvent):Void{
println("Rectangle");}
},
Button{
layoutX: 20 layoutY: 50
blocksMouse: true
text: "JustPrint"
action:function():Void{
println("JustPrint");}
},
btn = Button{
layoutX: 20 layoutY: 20
blocksMouse: true
text: "Cancel"
action:function():Void{
println("Cancel");
delete btn from theScene.content;}
},
]
}
}
当你按下“JustPrint”时,你会得到:
JustPrint
当你按下“取消”时,你会得到:
Cancel
Rectangle
【问题讨论】:
标签: javafx mouseevent