我希望有人可以幫助我解決一些小問題。我正試圖跟蹤鼠標在屏幕上的位置,我一直沒有問題。但是,當它通過一個按鈕時,它會停止跟蹤。有沒有人有任何想法可以解決這個問題?這裏是我試圖處理的更廣泛的問題的一個簡單的例子:JavaFX按鈕使鼠標事件消失
double x, y;
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage pStage) {
BorderPane bp = new BorderPane();
Scene scene = new Scene(bp, 500, 500);
pStage.setTitle("Show Circle");
pStage.setScene(scene);
pStage.show();
VBox centre = new VBox();
centre.setAlignment(Pos.CENTER);
centre.setPadding(new Insets(20, 20, 20, 20));
Button btn = new Button("hello");
centre.setPadding(new Insets(10, 10, 10, 10));
Label info = new Label("x: " + x + "\ny: " + y);
info.setPadding(new Insets(10, 10, 10, 10));
info.setFont(Font.font("Courier New", FontWeight.BOLD, 18));
centre.getChildren().addAll(info, btn);
bp.setCenter(centre);
x = 0;
y = 0;
scene.setOnMouseMoved(e -> {
x = e.getX();
y = e.getY();
info.setText("x: " + x + "\ny: " + y);
});
}
在此先感謝!
非常感謝! –