Search code examples
javahtmlimagejlabel

can JLabel have img tags


I am trying to display a JLabel which has a few lines of text and an image as follows:

String html = "<html> hello </br> <img src = \"/absolute/path/here\" height = \"30\"  width =\"40\"/> </html>";
JLabel l = new JLabel(html);

For the image all I get is a broken image, is it possible to nest img tags inside a JLabel?

EDIT: I want to add multiple images to the JLabel so I don't think the use of an ImageIcon will do here.

Thanks


Solution

  • Rather then try to have multiple images on a single JLabel why not simply have many JLabels, each with one image (as uthark described) and then group all the labels together on a single JPanel. That should give you the effect you are looking for with only minimal additional complexity.