Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用以下代码将本地驱动器中的图像用作工具提示,但它不显示图片:
String path = "C:/images/A.png"; labelIMG.setToolTipText("<html><img src='"+path+"'></html>");
任何解决此问题的方法,在此先感谢!
工具提示渲染需要一个 URL,而不是文件引用...
试试这样的东西。
String path = "C:/images/A.png"; File file = new File(path); labelIMG.setToolTipText("<html><img src='"+file.toURI().toURL()+"'></html>");
当然,您可以只使用一个简单的String,但在我脑海中它可能看起来像file:///c:/images/A.png(我现在不是 Windows 盒子,所以我无法检查,抱歉)
String
file:///c:/images/A.png