Events JavaFX窗口即使在被遮挡时也会不断接收鼠标移动事件

Events JavaFX窗口即使在被遮挡时也会不断接收鼠标移动事件,events,javafx,mouseevent,obscured-view,Events,Javafx,Mouseevent,Obscured View,JavaFX部分遮挡窗口是否仍应在被另一个窗口遮挡的窗口部分接收鼠标移动事件?这似乎是一种奇怪的行为。添加额外的窗口(同一应用程序或其他应用程序窗口中的javaFX)会导致奇怪和不可预测的行为 我做错什么了吗 有没有办法避免这种行为 package obscuredmouseevents; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextField

JavaFX部分遮挡窗口是否仍应在被另一个窗口遮挡的窗口部分接收鼠标移动事件?这似乎是一种奇怪的行为。添加额外的窗口(同一应用程序或其他应用程序窗口中的javaFX)会导致奇怪和不可预测的行为

我做错什么了吗

有没有办法避免这种行为

package obscuredmouseevents;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**
 *
 * @author michaelellis
 */
public class ObscuredMouseEvents extends Application {

    /**
     * After launching drag the mouse from left to right through the left edge
     * of the light blue panel of Window 1 and see the mouse coordinates
     * displayed in the text area at the bottom of Window 1. However, continue
     * dragging into the light blue panel of Window 2 and see not only the mouse
     * coordinates displayed in the text area at the bottom of Window 2, but
     * also the mouse coordinates displayed in the text area at the bottom of
     * Window 1.
     * <p>
     * Clicking in Window 2 stops mouse events being registered in Window 1,
     * however moving the mouse back into the light blue panel of Window 1, and
     * on into the light blue panel of Window 2 see the problem occur again.
     *
     * @param primaryStage
     */

    @Override
    public void start(Stage primaryStage) {
        createNewWindow("Window 1", 100, 100).show();
        createNewWindow("Window 2", 160, 120).show();
    }

    Stage createNewWindow(String title, int x, int y) {

        BorderPane root = new BorderPane();
        Rectangle r = new Rectangle(300, 200);
        r.setFill(Color.ALICEBLUE);
        root.setCenter(r);

        final TextField tf = new TextField();
        root.setBottom(tf);

        r.setOnMouseMoved(e -> {
            tf.setText(String.format("%d,%d", (int) e.getX(), (int) e.getY()));
            e.consume();
        });

        Scene scene = new Scene(root, 300, 300);
        Stage stage = new Stage();
        stage.setX(x);
        stage.setY(y);

        stage.setTitle(title);
        stage.setScene(scene);
        return stage;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

无法复制此问题。。。也许可以添加一些细节,如java版本、操作系统等。您是否尝试在鼠标进入、鼠标退出时实现?在Mac OS X 10.12.6、JDK 1.8.0上为我复制。我认为这可能与操作系统有关;这些窗口是“本机”的,并且几乎可以肯定,在操作系统级别确定哪些鼠标事件被传递到哪些窗口。通常,Mac和Windows的行为方式完全不同:例如,Mac上基于鼠标/触摸板的滚动通常指向滚动发生的窗口,而不管哪个窗口处于活动状态;Windows.OS-X El Capitan 10.11.6(15G1421)MacBook Pro(视网膜,15英寸,2013年初)java版本“1.8.0_121”java(TM)SE运行时环境(build 1.8.0_121-b13)java热点(TM)64位服务器虚拟机(build 25.121-b13,混合模式)的情况并非如此,这要感谢James_D对平台特定性质的理解。还有@zlakad,是的,我有一个更复杂的版本,可以捕捉鼠标进入/退出的事件,还有一些奇怪的事情发生在那里。我相信OS-X鼠标/窗口事件处理代码中存在一些bug。
package obscuredmouseevents;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class ObscuredMouseEvents extends Application {

    @Override
    public void start(Stage primaryStage) {
        createNewWindow("Window 1", 100, 100).show();
        createNewWindow("Window 2", 150, 120).show();
        createNewWindow("Window 3", 200, 140).show();
    }

    Stage createNewWindow(String title, int x, int y) {

        BorderPane root = new BorderPane();
        Rectangle r = new Rectangle(280, 240);
        r.setFill(Color.ALICEBLUE);
        root.setCenter(r);

        final CheckBox checkBox = new CheckBox("inside");
        root.setTop(checkBox);

        final TextField tf = new TextField();
        root.setBottom(tf);

        r.setOnMouseMoved(e -> {
            tf.setText(String.format("%d,%d", (int) e.getX(), (int) e.getY()));
            e.consume();
        });
        r.setOnMouseEntered(e -> {
            checkBox.setSelected(true);
            e.consume();
        });
        r.setOnMouseExited(e -> {
            checkBox.setSelected(false);
            e.consume();
        });

        Scene scene = new Scene(root, 300, 300);
        Stage stage = new Stage();
        stage.setX(x);
        stage.setY(y);

        stage.setTitle(title);
        stage.setScene(scene);
        return stage;
    }

    public static void main(String[] args) {
        launch(args);
    }

}