【发布时间】:2017-11-07 14:53:11
【问题描述】:
我有问题,我有BorderPane,在哪个中心有TabPane 和Tabs,还有其他各种Nodes(例如另一个BorderPane)。
当我尝试例如使用时:
parentBorderPane.setOnMouseDragged(e -> System.out.println("DRAGGING"));
parentBorderPane.setOnMouseMoved(e -> System.out.println("MOVING"));
...事件永远不会发生(我可以在当前打开的 Tab's 内容上捕捉到它们,但这不是我想要的)。
我需要知道此类事件何时在两个地方发生(第一个事件通过Tab 的内容,然后通过包含TabPane,然后通过主要父级BorderPane)。所以我不能使用(对任何孩子):
this.setMouseTransparent(true);
如何解决?
编辑
让我补充一点,主要问题在于TabPane - 它不会将事件传递到堆栈中的下一个节点。
编辑 2
public class T extends Application
{
public static void main(String[] args) throws Exception
{
launch(args);
}
@Override
public void start(Stage stage) throws Exception
{
stage.setTitle("Test");
Scene scene = new Scene(this.working()); // change to this.problem();
stage.setScene(scene);
stage.show();
}
private BorderPane working()
{
BorderPane main = new BorderPane();
main.setPrefSize(800, 600);
main.setOnMouseMoved(e -> System.out.println("MOVING ON MAIN"));
BorderPane sub = new BorderPane();
sub.setOnMouseMoved(e -> System.out.println("MOVING ON SUB"));
main.setCenter(sub);
return main;
}
private BorderPane problem()
{
BorderPane main = new BorderPane();
main.setPrefSize(800, 600);
main.setOnMouseMoved(e -> System.out.println("MOVING ON MAIN"));
BorderPane sub = new BorderPane();
sub.setOnMouseMoved(e -> System.out.println("MOVING ON SUB"));
main.setCenter(sub);
TabPane tabs = new TabPane();
tabs.setOnMouseMoved(e -> System.out.println("MOVING ON TABS"));
sub.setCenter(tabs);
return main;
}
}
working() - 正常的Panes 相互堆叠将正常工作(将事件从堆栈的顶部传递到底部)。
problem() - 因为TabPane 是 Control 的子类(我目前正在研究),所以它会停止鼠标事件并且不会让父母看到它们。
【问题讨论】:
-
向我们展示一个显示问题的最小工作程序将帮助我们更快地识别它。
-
@JKostikiadis 添加了示例代码。