简体   繁体   English

本地驱动器中图像的路径

[英]Path to an image in the local drive

I'm using the following code to use an image in my local drive as a tooltip but it does'nt show the picture : 我使用以下代码在我的本地驱动器中使用图像作为工具提示,但它没有显示图片:

String path = "C:/images/A.png";
labelIMG.setToolTipText("<html><img src='"+path+"'></html>");

any work around for this, thanks in advance! 任何解决此问题的工作,在此先感谢!

The tooltip render is expecting a URL, not a file reference... 工具提示呈现期望的是URL,而不是文件引用...

Try something like this instead. 尝试这样的事情。

String path = "C:/images/A.png";
File file = new File(path);
labelIMG.setToolTipText("<html><img src='"+file.toURI().toURL()+"'></html>");

You, could, of course, just use a simple String , but off the top of my head it might look something like file:///c:/images/A.png (I'm not a Windows box at the moment, so I can't check, sorry) 当然,你可以使用一个简单的String ,但是我的头顶可能看起来像file:///c:/images/A.png (我现在不是Windows的盒子,所以我不能检查,对不起)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM