且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JavaFX中将图像显示为工具提示?

更新时间:2023-01-15 19:02:57

如果您只是想要一个工具提示通过节点(在您的情况下为按钮),使用 工具提示 及其 graphicProperty 而不是显示不同的 Stage

If you just simply want to have a tooltip over a Node (a Button in your case), it is reasonable to use a Tooltip and its graphicProperty rather than showing a different Stage.

// Load the image with the needed size
Image image = new Image("...", 150, 150, true, true);

// Place it over a Button
Button button = new Button();

Tooltip tooltip = new Tooltip();
tooltip.setGraphic(new ImageView(image));

button.setTooltip(tooltip);