2009-11-01 71 views
0

如何显示我存储在JPanel的arraylist中的jpg图像?我不能在JPanel中显示jpg文件。在JPanel上显示jpg图像

String[] pictureFile = {"A.jpg","B.jpg","C.jpg"}; 
List<String> picList1 = Arrays.asList(pictureFile); 

Collections.shuffle(picList1); 

ImageIcon icon = new ImageIcon("picList1.get(0)"); 
JLabel label1 = new JLabel(); 
label1.setIcon(icon); 

JPanel panel = newJPanel; 
panel.add(label); 

回答

3

你不应该把数组的调用放在引号中。

相反,你应该尝试以下操作:

ImageIcon icon = new ImageIcon(picList1.get(0)); 
+0

谢谢...它的工作:-) – Jessy 2009-11-01 17:47:42

1

的问题是在该行

ImageIcon icon = new ImageIcon("picList1.get(0)"); 

它解释字符串作为文件名。您只需要取出picList1.get(0)位。