I'm creating rich text component with selection capabilities for JavaFX project and facing some difficulties.
I'm trying to catch on which TextFlow object user presses mouse button and on which another TextFlow he releases it. But after MOUSE_PRESSED event i can interact only with that TextFlow, who fired it, until i release the mouse.
Here is similar example with Labels:
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 " + label.getText()));
label.setOnMouseReleased(mouseEvent -> System.out.println("release mouse button on " + label.getText()));
}
//########################
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Try to move mouse over different Labels and watch messages in command line. After that press and hold mouse primary button on any Label and move it again. You'll see that no other Labels will fire any event until you releases the button.
I spend some time searching for the solution but got nothing.
I also tried to manually fire MOUSE_RELEASED for corresponding Label but it didn't help also.
Appreciate your support.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…