我试过了:
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);
}
有人可以解释我为什么我的工具提示不起作用 - 我不知道我做错了什么。 (这是我第一次使用Tooltips)
有人告诉我,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);
}
答案 0 :(得分:6)
安装工具提示到图像视图正在运行。尝试使用新的JavaFX示例项目并查看它。当您怀疑所使用的API的某些功能(在这种情况下是JavaFX)时,尝试将怀疑的用例隔离到新的新环境/项目中并密切观察它。
P.S。为什么要从leftSide中删除targetCardBox并在之后再次添加。