tags:

views:

359

answers:

2

How can I display jpg image which I stored in arraylist in JPanel? Im not able to display the jpg files in the JPanel.

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);
+1  A: 

The problem is in the line

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

It's interpreting the string as a file name. You should just need to unquote the picList1.get(0) bit.

Jim Downing
+2  A: 

You should not put the call to the array in quotes.

Instead, you should try the following:

ImageIcon icon = new ImageIcon(picList1.get(0));
akf
Thank you...it's work :-)
Jessy