Relative path in JLabel HTML
Posted
by kroiz
on Stack Overflow
See other posts from Stack Overflow
or by kroiz
Published on 2009-10-20T10:34:28Z
Indexed on
2010/04/29
11:37 UTC
Read the original article
Hit count: 252
Hi, I am trying to make JLabel show an html which is referencing an image using a relative path. But I cannot make JLabel locate the image. It works fine when I am using absolute path.
I have tried running the program from the command line or from eclipse and add dialog to show me where is the current working directory but for avail. I have therefor came to the conclusion that the image is not searched in the current directory - which brings me to the point. where is the image looked for?
here is a test code that show what I am doing:
import javax.swing.*;
public class HTMLLabel extends JFrame {
public HTMLLabel() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JOptionPane.showMessageDialog( this,
System.getProperty("user.dir"));
String html = "<html>\n" +
" <body>\n" +
" <div style=\"text-align: center;\">\n" +
" <img src=\"file://s.png\">\n"+
" </div>\n"+
" </body>\n"+
"</html>";
JLabel label = new JLabel(html);
add(label);
pack();
setVisible(true);
}
public static void main(String[] args) {
new HTMLLabel();
}
}
© Stack Overflow or respective owner