简体   繁体   中英

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...

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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