add two at the beginning, set the second to be invisible.
when you detect the value change event, 
comb2.clearAll();
comb2.add(whatever);
comb2.setvisible(true);

解决方案 »

  1.   

    不太好用,我的代码如下: 请给支几招,谢了
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    /*
    <applet code=test.class codebase=F:/j/ width=200 height=300 >
    </applet>
    */
    public class test extends JApplet implements ListSelectionListener
    {
    JList lt;
    JList lt2;
    Container conPane;
    JScrollPane jsp2;
    public void init()
    {
    conPane=getContentPane();
    String[] items=new String[12];

    for(int i=0; i<11; i++)
    items[i]="ii";

    lt=new JList(items);
    lt2=new JList(items);

    JScrollPane jsp=new JScrollPane(lt);
    lt.setVisibleRowCount(5);
    lt.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    lt.addListSelectionListener(this);

    jsp2=new JScrollPane(lt2);
    lt2.setVisibleRowCount(5);
    lt2.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    lt2.addListSelectionListener(this);

    conPane.setLayout(new FlowLayout());
    conPane.add(jsp);
    conPane.add(jsp2);
    jsp2.setVisible(false);
    }

    public void valueChanged(ListSelectionEvent e)
    {
    int[] index=lt.getSelectedIndices();
    String[] items=new String[12];

    jsp2.setVisible(true);
    repaint();
    }
    }