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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With