Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8124076

TextFlow does not properly forward MouseEvents to its Text nodes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 8
    • javafx
    • Using Lombard b89 on Windows 8.

    Description

      I'm trying to implement my own flowing hyperlink text in a TextFlow object, by listening for MouseClick events on the individual Text nodes in the TextFlow. Unfortunately, many of those MouseClick events seem to be going to the wrong Text node (i.e. I will click on the text of one Text node, and a different Text node will receive the click!)

      Here is some sample code that demonstrates the problem:

      public class TextFlowBug extends Application {
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
              primaryStage.setTitle("Hello World!");
              TextFlow tflow = new TextFlow();
              tflow.getChildren().addAll(
                 createText("Start line 1, "),
                 createText("end line 1\n\n"),
                 createText("Start line 2, "),
                 createText("end line 2\n"),
                 createText("[Start line 3], "),
                 createText("[end line 3]\n\n") );
              StackPane root = new StackPane();
              root.getChildren().add(tflow);
              primaryStage.setScene(new Scene(root, 300, 250));
              primaryStage.show();
          }
          
          private Text createText(final String msg) {
             Text t = new Text(msg);
             t.setOnMouseClicked( new EventHandler<MouseEvent>() {
                public void handle(MouseEvent event) {
                   System.out.println( "CLICKED ON: '" + msg.trim() +"'" );
                }
             } );
             return t;
          }
      }

      To see the problem, try clicking on the various text nodes. In this simple example, you'll see that clicking on either "Start Line 1" and "[Start Line 3]" will send the MouseClick event to a different Text node.

      Attachments

        Activity

          People

            fheidric Felipe Heidrich (Inactive)
            cbanackjfx Cory Banack (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: