我想显示图像作为工具提示。它工作正常,但在某些随机点它显示出波动。我想正常显示而不出现波动。
我在鼠标输入事件上显示一个新场景(其中我添加了带有图像的图像视图)并在鼠标离开事件事件上关闭它
// MOUSE ENTER PHOTO CORRECTIO
@FXML
private void mouseEnterPhotoCorrection(MouseEvent event) {
if (f_ShowToolTip) {
Stage stg = funShowImageTooltip();
double x, y;
x = event.getScreenX();
y = event.getScreenY();
stg.setX(x);
stg.setY(y);
stg.show();
f_ShowToolTip = false;
}
}
// MOUSE LEAVE PHOTO CORRECTIO
@FXML
private void mouseLeavePhotoCorrection(MouseEvent event) {
funHideImageTooltip();
f_ShowToolTip = true;
}
/****************************** 功能 ****************** **************/
Stage s;
boolean f_ShowToolTip;
// FUNCTION TO SET INITAL STATE OF PHOTOS AND CORRECTION
private void funInitPhotosCorrection()
{
f_ShowToolTip = true;
}
private Stage funShowImageTooltip()
{
try {
s = new Stage();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("frmImageToolTip.fxml"));
Parent root = (Parent) fxmlLoader.load();
Scene scene = new Scene(root);
s.setScene(scene);
s.setResizable(false);
s.initModality(Modality.WINDOW_MODAL);
s.initStyle(StageStyle.UNDECORATED);
s.setResizable(false);
double x, y;
//x = btn_Red.
s.show();
}catch(Exception e1)
{
}
return s;
}
private void funHideImageTooltip()
{
try {
s.close();
} catch (Exception e) {
}
}
如果您只是想要一个工具提示Node
(a Button
在你的情况下),使用是合理的Tooltip https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Tooltip.html和它的graphicProperty https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Tooltip.html#graphicProperty--而不是表现出不同的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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)