2013-12-14 42 views
-2
JOptionPane.showMessageDialog(null, "<html><body><img src=\"pacman.png\"></body></html>"); 

該目錄是有效的,我的記事本中的html代碼工作。爲什麼標記不能在Java組件中使用,比如JLabel和JOptionPane?在JOptionPane和JLabel

+0

的IMG參考需要的URL生成 – MadProgrammer

回答

0

可以使用的ImageIcon把圖像的JOptionPane

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); 
      } 
     } 
0

JOptionPane.showMessageDialog()第二個參數是要在對話框中放置對象內。你只是發送一個字符串。

HTML工作在JLabel所以下面的代碼片段應該工作:

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