java JList选项显示问题
程序段如下:rb[0].addActionListener(newActionListener(){publicvoidactionPerformed(ActionEve...
程序段如下:rb[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
dl.clear();
for(k=0;k<81;k++)
dl.add(k,"["+k+"]"+" "+ls[k]);
list.setModel(dl);
if(rb[0].isSelected()){
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
tp.setText(null);
if(list.getSelectedIndex()!=-1)
{
tp.setText(null);
insertDocument(list.getSelectedValue()+"\n",Color.BLUE,tp,true);
insertDocument(rda[list.getSelectedIndex()]+"\n",Color.BLUE,tp,true);
}
else if(list.getSelectedIndex()==-1)
tp.setText("你没选择选项!");
}
});
}
}
});
rb[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
dl.clear();
for(k=0;k<78;k++)
{m=k+81;
dl.add(k,"["+m+"]"+" "+ls[m]);
}
tp.setText(null);
list.setModel(dl);
if(rb[1].isSelected()){
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
tp.setText(null);
if(list.getSelectedIndex()!=-1)
{
tp.setText(null);
insertDocument(list.getSelectedValue()+"\n",Color.BLUE,tp,true);
insertDocument(rda[list.getSelectedIndex()+81]+"\n",Color.RED,tp,true);
}
else if(list.getSelectedIndex()==-1)
tp.setText("你没选择选项!");
}
});
}
}
});
我先点击按钮rb[0],再点击rb[1],却在tp中显示使用了rb[0]中的list的索引,因为dl发生变化,list自然也发生变化,我是想用rb[1]的索引,为什么程序却用的还是rb[0]的索引呢,我确实用了dl.clear(),难道这个方法并没有把原来的索引表清除么,请问有人知道怎么搞么?还望不吝赐教啊!在线等,急! 展开
public void actionPerformed(ActionEvent e)
{
dl.clear();
for(k=0;k<81;k++)
dl.add(k,"["+k+"]"+" "+ls[k]);
list.setModel(dl);
if(rb[0].isSelected()){
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
tp.setText(null);
if(list.getSelectedIndex()!=-1)
{
tp.setText(null);
insertDocument(list.getSelectedValue()+"\n",Color.BLUE,tp,true);
insertDocument(rda[list.getSelectedIndex()]+"\n",Color.BLUE,tp,true);
}
else if(list.getSelectedIndex()==-1)
tp.setText("你没选择选项!");
}
});
}
}
});
rb[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
dl.clear();
for(k=0;k<78;k++)
{m=k+81;
dl.add(k,"["+m+"]"+" "+ls[m]);
}
tp.setText(null);
list.setModel(dl);
if(rb[1].isSelected()){
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
tp.setText(null);
if(list.getSelectedIndex()!=-1)
{
tp.setText(null);
insertDocument(list.getSelectedValue()+"\n",Color.BLUE,tp,true);
insertDocument(rda[list.getSelectedIndex()+81]+"\n",Color.RED,tp,true);
}
else if(list.getSelectedIndex()==-1)
tp.setText("你没选择选项!");
}
});
}
}
});
我先点击按钮rb[0],再点击rb[1],却在tp中显示使用了rb[0]中的list的索引,因为dl发生变化,list自然也发生变化,我是想用rb[1]的索引,为什么程序却用的还是rb[0]的索引呢,我确实用了dl.clear(),难道这个方法并没有把原来的索引表清除么,请问有人知道怎么搞么?还望不吝赐教啊!在线等,急! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询