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

Tooltip on ImageView does not work when inside a ListView/TableView

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u40
    • javafx
    • None

      Consider and run the code below (you have to provide valid image paths).

      The exact same ImageView shows a tooltip, when added directly to the scene. But ImageView does not show a Tooltip, when set as graphic of a ListCell.


      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.ListCell;
      import javafx.scene.control.ListView;
      import javafx.scene.control.Tooltip;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class TestApp2 extends Application {

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

          @Override
          public void start(final Stage stage) throws Exception {


              ListView<String> listView = new ListView<>();
              listView.setItems(FXCollections.observableArrayList("test", "test"));
              listView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
                  @Override
                  public ListCell<String> call(ListView<String> stringListView) {
                      return new ListCell<String>() {
                          @Override
                          protected void updateItem(String item, boolean empty) {
                              super.updateItem(item, empty);
                              setGraphic(null);
                              if (!empty) {
                                  ImageView imageView = new ImageView();
                                  imageView.setImage(new Image("image.png"));
                                  // Does NOT work as expected:
                                  Tooltip.install(imageView, new Tooltip("That's a test"));
                                  setGraphic(imageView);
                              }
                          }
                      };
                  }
              });

              ImageView imageView = new ImageView();
              imageView.setImage(new Image("image.png"));
              // Works as expected:
              Tooltip.install(imageView, new Tooltip("That's a test"));

              Scene scene = new Scene(new VBox(imageView, listView));
              stage.setScene(scene);
              stage.show();
          }
      }

            Unassigned Unassigned
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported: