tengo un problema, necesito mostrar imagenes en un jlist, algo como un visor de imagenes, tengo casi listo pero no me muestra las imagenes ayuda porfavor
aqui va el codigo
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class JListSample extends JFrame implements ListSelectionListener
{
// Used in choosing selection. Each String name corresponds to a given image
String [] nombres = { "1","2","3","4","5" };
// be sure to save these images within the same directory of this java file
ImageIcon [] fotos = { new ImageIcon ("1.jpg"),
new ImageIcon ("2.jpg"),
new ImageIcon ("3.jpg"),
new ImageIcon ("4.jpg"),
new ImageIcon ("5.jpg") };
BorderLayout layoutBL;
JList lista;
JScrollPane selectionJS;
JLabel etiqueta, displayPicJL, infoJL;
public JListSample ()
{
super ("visor de fotos");
Container panel = getContentPane ();
panel.setLayout (null);
etiqueta = new JLabel ("elige una foto", SwingConstants.CENTER);
etiqueta.setSize (470,20);
etiqueta.setLocation (10,0);
panel.add (etiqueta);
lista = new JList (nombres);
lista.setVisibleRowCount (3);
lista.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
lista.addListSelectionListener (this);
selectionJS = new JScrollPane (lista);
selectionJS.setSize (470,60);
selectionJS.setLocation (10,20);
panel.add (selectionJS);
displayPicJL = new JLabel (fotos[4]);
displayPicJL.setSize (470,350);
displayPicJL.setLocation (10,50);
panel.add (displayPicJL);
infoJL = new JLabel (nombres [4], SwingConstants.CENTER);
infoJL.setSize (470,20);
infoJL.setLocation (10,380);
panel.add (infoJL);
setSize (500,440);
setVisible (true);
setDefaultCloseOperation (EXIT_ON_CLOSE);
}
public static void main (String [] args){
JListSample list = new JListSample ();
}
public void valueChanged (ListSelectionEvent e){
if (e.getSource() == lista)
{ displayPicJL.setIcon (fotos[lista.getSelectedIndex()]);
infoJL.setText (nombres[lista.getSelectedIndex()]);
}
}
}