首页javajlabelJava Swing - 如何从带有img标签的HTML创建JLabel

Java Swing - 如何从带有img标签的HTML创建JLabel

我们想知道如何从带有img标签的HTML创建JLabel。
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main{
  public static void main(String[] args)  {
      JFrame frame = new JFrame();
      frame.setLayout(new BorderLayout());
      JLabel label = new JLabel(
          "<html>"
          + "<img src=\""
          + Main.class.getResource("/resource/path/to/image1.jpg")
          + "\">"
          + "<img src=\""
          + Main.class.getResource("/resource/path/to/image2.jpg")
          + "\">"
          + "The text</html>");
      frame.add(label, BorderLayout.CENTER);
      frame.setBounds(100, 100, 200, 100);
      frame.setVisible(true);
   }
 }