I have a swing app that has several tabs. It has a Jlist in which I want to display a different image each time the tab is changed. When I run the app, the image is displayed that corresponds to the first tab. However when I click another tab, the image stays the same, rather than change.


Here is where I create the tabs and have the tab change listener.
Java Code:
public MainFrame() {	
		
		setTitle("My Game Collection");

		Image ltreeImage = Toolkit.getDefaultToolkit().getImage(
				"images/ltree_icon.gif");
		setIconImage(ltreeImage);

		Container container = this.getContentPane();
		container.setLayout(new BorderLayout());

		tabbedPane = new JTabbedPane();
       	snes = new GamePanelGUI(new JFrame());
		tabbedPane.addTab("Snes", snes);
			
		nes = new GamePanelGUI(new JFrame());
		tabbedPane.addTab("NES",nes);
		
		sega = new GamePanelGUI(new JFrame());
		tabbedPane.addTab("SEGA", sega);

		sega32x = new GamePanelGUI(new JFrame());
		tabbedPane.addTab("SEGA32X", sega32x);
		
		sms = new GamePanelGUI(new JFrame());
		tabbedPane.addTab("SMS", sms);
	
		container.add(BorderLayout.CENTER , tabbedPane);

		setSize(500, 400);
		setLocation(100, 100);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						
		tabbedPane.addChangeListener(new ChangeListener() {

			public void stateChanged(ChangeEvent evt) {
				JTabbedPane tabbedPane = (JTabbedPane) evt.getSource();

				sel = tabbedPane.getSelectedIndex();
				title = tabbedPane.getTitleAt(sel);
				System.out.println("Tab Changed to." + title);
				img = new GamePanelGUI(new JFrame());       		
        	}
		});
		
	}
Here is where I have the Jlist where I try to load the different images.
Java Code:
public GamePanelGUI(JFrame theParentFrame){	
...
gameListBox = new JList();
		gameListBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	 	
		musicScrollPane = new JScrollPane(gameListBox);

//set the cell renderer
gameListBox.setCellRenderer(new ImageListCellRenderer());

if(gameListBox.getModel().getSize() <1)
		{
		int x = MainFrame.sel;
		if(x == 0){	
		snesIcon = (new ImageIcon("C:\\Users\\mfierro\\Desktop\\crs471\\SourceCode\\Solution - ex71\\images\\snes.jpg" ));
		System.out.println(snesIcon);
		snesLabel = new JLabel(snesIcon,JLabel.CENTER) ;
		snesPanel = new JPanel();
		snesPanel.add(snesLabel);
		gameListBox.setListData(getPanel().toArray());
		
		}
		
		if(x == 1){	
	
			nesIcon = (new ImageIcon("C:\\Users\\mfierro\\Desktop\\crs471\\SourceCode\\Solution - ex71\\images\\nes.jpg" ));
			System.out.println(nesIcon);
			nesLabel = new JLabel(nesIcon,JLabel.CENTER) ;
			nesPanel = new JPanel();
			nesPanel.add(nesLabel);
			gameListBox.repaint();
			gameListBox.setListData(getPanel().toArray());
		
		}
		
		}
}

public ArrayList<Object>getPanel(){
		
		ArrayList<Object> obj = new ArrayList<Object>();
	 
		int y = MainFrame.sel;
		System.out.println("Value of sel in getPanel:" + y);
		
		if (MainFrame.sel == 0){
		Object item = snesPanel;
		obj.add(item);
		}
		
		if (MainFrame.sel == 1){
			Object item = nesPanel;
			obj.add(item);
		}
		 System.out.println("The # of objects is:" + obj.toArray());					 
		 System.out.println("This is in logoPanel" + obj.toString());
	    return obj;
	}
	
	public String getImgName(){
		System.out.println ("In getImg method.  tab value is:" + MainFrame.sel);
		String imgName = "";
         if(MainFrame.sel == 0){
        //	categoryComboBox.setSelectedIndex(0); 
			imgName = "snes.jpg";
		    return imgName;
		}
     	if(MainFrame.sel == 1){
		  imgName = "nes.jpg";
		  return imgName;
	    }
     	
     	else{
     		return imgName;
     	}	
	}

Here is the ListCellRenderer
Java Code:
class ImageListCellRenderer implements ListCellRenderer
	{
	  
	   
	  public Component getListCellRendererComponent(JList jlist, 
	                                                Object value, 
	                                                int cellIndex, 
	                                                boolean isSelected, 
	                                                boolean cellHasFocus)
	  {
		  
				  
	    if (value instanceof JPanel)
	    {
	   
	      Component component = (Component) value;
	      component.setForeground (Color.white);
	      component.setBackground (Color.white);
	      return component;
	    }
	    else
	    {
	    	return new JLabel("???");
	    }
	  }
	}