Relative path in JLabel HTML
- by kroiz
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();
    }
}