小编blu*_*pun的帖子

从一个节点获取MOUSE_PRESSED事件后,无法从任何其他javafx 8节点获取鼠标事件

我正在创建富文本组件,其中包含JavaFX项目的选择功能并面临一些困难.我试图抓住哪个TextFlow对象用户按下鼠标按钮,然后另一个TextFlow释放它.但是在MOUSE_PRESSED事件之后,我只能与那个解雇它的TextFlow进行交互,直到我释放鼠标.

以下是标签的类似示例:

package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        AnchorPane root = new AnchorPane();
        primaryStage.setTitle("Events Problem Example");
        primaryStage.setScene(new Scene(root, 800, 600));

        VBox mainVB = new VBox();
        root.getChildren().add(mainVB);

        //########## Code is here:
        for (int i = 0; i < 5; i++) {
            final Label label = new Label("label?"+i);
            mainVB.getChildren().addAll(label);

            label.setOnMouseEntered(mouseEvent -> System.out.println("entering " + label.getText()));
            label.setOnMousePressed(mouseEvent -> System.out.println("press mouse button on …
Run Code Online (Sandbox Code Playgroud)

mouseevent javafx-8

3
推荐指数
1
解决办法
2435
查看次数

标签 统计

javafx-8 ×1

mouseevent ×1