有这样的代码:
public void valueChanged(ListSelectionEvent e)
{
System.out.println("FirstIndes:"+e.getFirstIndex());
System.out.println("LastIndes:"+e.getLastIndex());
                        }
为什么每次改变时它都要打印两次啊??不懂#_#

解决方案 »

  1.   

    这样改一下
    public void valueChanged(ListSelectionEvent e){
        if (!e.getValueIsAdjusting()) {
            System.out.println("FirstIndes:"+e.getFirstIndex());
            System.out.println("LastIndes:"+e.getLastIndex());
        }
    }
      

  2.   

    valueChanged说的是,选中时,即一次变化,值为选中,值变了,从没选中变成选中,当选另一个list的item时,他的值为没选中,值也变了,所以一共变化了两次。