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

标签 java imageview javafx tooltip

我试过这个:

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

有人能解释一下为什么我的工具提示不起作用 - 我不知道我做错了什么。 (这是我第一次使用工具提示)


其他人告诉我 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);
}

最佳答案

安装工具提示到 ImageView 是有效的。尝试使用新的示例 JavaFX 项目并查看它。当您对所用 API(在本例中为 JavaFX)的某些功能有疑问时,请尝试将有疑问的用例隔离到新的环境/项目中并仔细观察它。

附言为什么要从 leftSide 中删除 targetCardBox 然后再添加它。

关于JavaFx:如何在 ImageView 上安装工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22604874/

相关文章:

Java 随着时间的推移逐渐减少数量直到达到目标

java - 在 Java 中从 PNG 到 JPG 的转换将白色变为红色

java - 在 JList 失去焦点后保留 JList 选择?

android - 根据图像大小调整 ImageViews 的大小

java - 如何在回调类中传递不同的泛型?

警告对话框中的 JavaFX 默认聚焦按钮

java - HashMap.keySet() 如何返回键的 View ?

bitmap - getDrawable() 在尝试从 imageview 获取位图时给出空对象

ios - 在 ios 中使用整数变量来命名图像

linux - 找不到错误 : Module java. base,在 Fedora 上尝试 jlink 时需要