简体   繁体   English

JavaFx:如何在ImageView上安装工具提示

[英]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) (这是我第一次使用Tooltips)


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 有人告诉我,ImageView不能使用工具提示并给我这个解决方法 - 但当我用鼠标移动标签时,我再次没有工具提示

    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);
}

Installing a tooltip to image view is working. 安装工具提示到图像视图正在运行。 Try yourself with new sample JavaFX project and see it. 尝试使用新的JavaFX示例项目并查看它。 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. 当您怀疑所使用的API的某些功能(在这种情况下是JavaFX)时,尝试将怀疑的用例隔离到新的新环境/项目中并密切观察它。

PS Why are you removing the targetCardBox from leftSide and adding it again afterwards. PS为什么要从leftSide中删除targetCardBox并在之后再次添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM