ListSelectionListener インターフェイスを実装する次のクラスを作成しました。このクラスは、作成した JList の選択イベントを「リッスン」する必要があります。ユーザーがこのリストの行をクリックするたびに、selected_row の値が更新され、文字列 "The format row selected is ...." が変更されます。ただし、行を複数回クリックしても、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]);
}
}
}
}