Viendo la imagen jpg en JPanel
Pregunta
¿Cómo puedo mostrar la imagen jpg, que guardé en ArrayList en JPanel? No soy capaz de mostrar los archivos jpg en el 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);
Solución
No debe poner la llamada a la matriz entre comillas.
En su lugar, usted debe tratar lo siguiente:
ImageIcon icon = new ImageIcon(picList1.get(0));
Otros consejos
El problema está en la línea
ImageIcon icon = new ImageIcon("picList1.get(0)");
Es la interpretación de la cadena como un nombre de archivo. Usted sólo debe necesitar Unquote el bit picList1.get(0)
.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow