我创建了以下实现 ListSelectionListener 接口的类。这个类应该“监听”我创建的 JList 的选择事件。每次用户单击此列表的一行时,都应更新 selected_row 值,因此字符串“所选格式行是 ....”应更改。但是,在多次单击行后,select_row 值不会改变。任何人都可以为此提供一个解释,并希望能提供一种方法来做我想做的事吗?提前致谢!!
import java.util.List;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import ee.dobax.portal.CommonPath;
public class FormatListSelectionListener implements ListSelectionListener{
public ContentGenerated content;
private CommonPathList path_list;
private ConfigRenderingDialog dialog;
public FormatListSelectionListener(ConfigRenderingDialog dialog){
content = dialog.content;
path_list = dialog.pathList;
}
public void valueChanged(ListSelectionEvent e) {
int selected_row;
if(e.getValueIsAdjusting() == false){
selected_row = e.getLastIndex();
System.out.println("The format row selected is "+selected_row);
path_list.addFormatListRowSelected(selected_row);
List<CommonPath> list_p = content.getPathList(selected_row);
Object[] path_list_to_array = new Object[list_p.size()];
path_list.getContents().removeAllElements();
for(int x = 0; x < list_p.size(); x++){
path_list_to_array[x] = list_p.get(x);
path_list.getContents().addElement(path_list_to_array[x]);
}
}
}
}