8

I tried this:

public void addTargetCard(MissionCard mCard) {
    int card = mCard.GetID();
    leftSide.getChildren().removeAll(targetCardBox);
    Image image = new Image(
            MainApp.class.getResourceAsStream("images/target" + card
                    + ".png"));
    ImageView imageView = new ImageView();
    imageView.setImage(image);
    imageView.setFitHeight(81);
    imageView.setFitWidth(108);
    imageView.setPreserveRatio(true);
    imageView.setPickOnBounds(true);
    Tooltip.install(imageView, new Tooltip(intToCity(mCard.getStart())
            + " - " + intToCity(mCard.getFinish())));
    targetCardBox.getChildren().add(imageView);
    leftSide.getChildren().add(targetCardBox);
}

Can somebody explain me why my Tooltip doesn't work - i got no idea what i did wrong. (It's my first time that i use Tooltips's)


somebody else told me that ImageView doesnt work with tooltips and gave me this workaround - but i have again no tooltip when i move with my mouse over the label

    public void addTargetCard(MissionCard mCard) {
    int card = mCard.GetID();
    leftSide.getChildren().removeAll(targetCardBox);
    Image image = new Image(
            MainApp.class.getResourceAsStream("images/target" + card
                    + ".png"));
    ImageView imageView = new ImageView();
    imageView.setImage(image);
    imageView.setFitHeight(81);
    imageView.setFitWidth(108);
    imageView.setPreserveRatio(true);
    imageView.setPickOnBounds(true);
    Label label = new Label();
    label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    label.setGraphic(imageView);
    label.setTooltip(new Tooltip(intToCity(mCard.getStart()) + " - "
            + intToCity(mCard.getFinish())));
    targetCardBox.getChildren().add(label);
    leftSide.getChildren().add(targetCardBox);
}
2
  • Have you tried a simple example of tooltip on label and on imageview? Please show some effort. Have you any css styles that maybe causing the tooltip not to appear?
    – Uluk Biy
    Mar 24, 2014 at 17:08
  • i tried a simple example i just dont had the right idea why i have no tooltip in that example
    – baxbear
    Mar 25, 2014 at 0:09

1 Answer 1

7

Installing a tooltip to image view is working. Try yourself with new sample JavaFX project and see it. When you doubt about some functionality of the used API (JavaFX in this case) try to isolate the doubted use case into new fresh environment/project and observe it closely.

P.S. Why are you removing the targetCardBox from leftSide and adding it again afterwards.

4
  • hmm k, I remove targetCardBox add it again because there is an update function that updates the content all the time
    – baxbear
    Mar 24, 2014 at 10:40
  • your p.s. was the best hint^^ - because i always update the targetcards there wasn't enough time to show a tooltip between two updates - thank you for your help^^
    – baxbear
    Mar 24, 2014 at 23:47
  • 1
    I don't think this is correct. ImageView is not a Control which has the tooltip property, it is a Node.
    – Nick B
    Jun 3, 2019 at 2:01
  • Tooltip.install(imageView, string) does work on ImageView Nodes. Sep 16, 2020 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.