How to link two Jlist with a MouseClick event
<p>in my code i'm creating a Jlist with A and B and i'm trying to construct a JList depending on what the user will click( A or B ). So if the user clicks A then i want list2 to appear in my frame. If he clicks B then list3 must appear. But right now i have to click to the frame in order for the list to appear.  Can someone explain to me how is this possible and what's wrong with my code?</p>

<pre><code>import java.awt.*;       
import java.awt.event.*; 
import javax.swing.*; 


public class test extends JFrame implements MouseListener
{
    private static JList list1 = new JList();
    private static JList list2 = new JList();
    private static JList list3 = new JList();
    private static JPanel jp1;
    private static JScrollPane listScroller2,listScroller3;
    private DefaultListModel listModel1,listModel2,listModel3;

    public test() 
    {
    setTitle("Menu");
    JTabbedPane jtp = new JTabbedPane();
    setSize(600,600);
    getContentPane().add(jtp);
    jp1 = new JPanel(); 
    jp1.setLayout(new BorderLayout());


    listModel1 = new DefaultListModel();
    listModel1.addElement("A");
    listModel1.addElement("B");

    list1 = new JList(listModel1);
    JScrollPane listScroller1 = new JScrollPane(list1); 
    listScroller1.setPreferredSize(new Dimension(100, 100));  
    jp1.add(listScroller1, BorderLayout.WEST);

    listModel2 = new DefaultListModel();
    listModel2.addElement("A1");
    listModel2.addElement("A2");


    list2 = new JList(listModel2);
    listScroller2 = new JScrollPane(list2); 
    listScroller2.setPreferredSize(new Dimension(100,100));  


    listModel3 = new DefaultListModel();
    listModel3.addElement("B1");
    listModel3.addElement("B2");


    list3 = new JList(listModel3);
    listScroller3 = new JScrollPane(list3); 
    listScroller3.setPreferredSize(new Dimension(100,100));  


    jtp.addTab("Letters", jp1);

    list1.addMouseListener(this); 
    }

    public void mouseClicked(MouseEvent e) 
    {
        int i = list1.getSelectedIndex();
        if(i == 0)
        {
            jp1.add(listScroller2, BorderLayout.CENTER); 
        }
        else if ( i == 1 )
        {
            jp1.add(listScroller3, BorderLayout.CENTER); 
        }
    }

public void mouseExited(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
public void mouseReleased(MouseEvent event){}
public void mousePressed(MouseEvent event){}


     public static void main(String[] args) 
     {
        test tp = new test();
        tp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        tp.setVisible(true);

     }
}
</code></pre>

<p>Edit: And how to switch through the lists all the time and not just staying in list2 or list3?</p>