Javafx工具提示太大时闪烁

时间:2019-04-20 12:56:58

标签: java javafx

我想显示一个小图像,并在小图像悬停时以原始尺寸显示图像。

Gif

我需要一个工具提示,因为原始尺寸的图像无法容纳窗口。

可执行代码:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        String bigImageUrl = "https://cdn.lynda.com/course/184457/184457-636806635954727169-16x9.jpg";
        String smallImageUrl = "https://assets.exercism.io/tracks/java-bordered-turquoise.png";

        VBox root = new VBox();
        root.getChildren().add(loadTooltipWithImage(smallImageUrl));
        root.getChildren().add(loadTooltipWithImage(bigImageUrl));
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }

    private Label loadTooltipWithImage(String url) {
        ImageView bigImage = new ImageView(new Image(url));
        ImageView smallImage = new ImageView(new Image(url));
        smallImage.setFitHeight(100.0);
        smallImage.setFitWidth(100.0);

        Label label = new Label();
        label.setGraphic(smallImage);

        Tooltip tooltip = new Tooltip();
        tooltip.setGraphic(bigImage);
        label.setTooltip(tooltip);
        return label;
    }
}

当节点悬停时,工具提示会显示图像,但是当图像太大时,鼠标无法悬停该节点:

  1. 节点悬停
  2. 工具提示显示图像
  3. 该节点未悬停
  4. 工具提示不显示
  5. 转到步骤1

我尝试过的事情:

  • 在工具提示上将鼠标透明设置为true,但我不能
  • 使用窗格而不是工具提示,但是窗口(阶段)对于图像而言太小了
  • 设置鼠标过滤器,但它们对我没有帮助

0 个答案:

没有答案
相关问题