Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFx: How to install a Tooltip on ImageView

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);
}
like image 340
baxbear Avatar asked Mar 24 '14 09:03

baxbear


1 Answers

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.

like image 114
Uluk Biy Avatar answered Sep 17 '22 00:09

Uluk Biy