Java <;img>;在JOptionPane和JLabel中 JOptionPane.showMessageDialog(null,”);

Java <;img>;在JOptionPane和JLabel中 JOptionPane.showMessageDialog(null,”);,java,html,swing,joptionpane,Java,Html,Swing,Joptionpane,目录是有效的,我的记事本中的html代码可以正常工作。为什么标签在Java组件(如JLabel和JOptionPane)中不起作用?您可以使用ImageIcon将图像放入JOptionPane JOptionPane.showMessageDialog(null, "<html><body><img src=\"pacman.png\"></body></html>"); JOptionPane.showMessageDialog()

目录是有效的,我的记事本中的html代码可以正常工作。为什么标签在Java组件(如JLabel和JOptionPane)中不起作用?

您可以使用ImageIcon将图像放入JOptionPane

JOptionPane.showMessageDialog(null, "<html><body><img src=\"pacman.png\"></body></html>");

JOptionPane.showMessageDialog()的第二个参数是要放置在对话框中的对象。你只是在发送一个字符串

HTML在JLabel中工作,因此以下代码段应该可以工作:

    public class Test
        {
            public static void main(String[] args)
            {
 -> //Url link for the image   //ImageIcon icon = new ImageIcon(new URL("http://www.gravatar.com/avatar/a1ab0af4997654345d7a949877f8037e?s=128&d=identicon&r=PG"));
                final ImageIcon icon = new 

ImageIcon("C:\\Users\\John\\Desktop\\pacemen.jpg");
                JOptionPane.showMessageDialog(null, "Blah blah blah", "About", JOptionPane.INFORMATION_MESSAGE, icon);
            }
        }
JOptionPane.showMessageDialog(null,新JLabel(“”);

需要将img引用生成为URL
JOptionPane.showMessageDialog(null, new JLabel("<html><body><img src=\"pacman.png\"></body></html>"));