3つのJListリストを使用してJDialogを作成しました。最初のリスト(FirstListという名前)で行を選択すると、2番目のリスト(SecondList)のコンテンツが更新され、2番目のリストで行を選択すると3番目のリスト(ThirdList)のコンテンツが更新されます。ThirdListクラスには、次のメソッドが含まれています。
public void addRowsSelected(int format_row, int pathway_row){
first_list_selected_row = fl_row;
second_list_selected_row = sl_row;
ListSelectionModel listSelectionModel = this.getSelectionModel();
listSelectionModel.addListSelectionListener(new ThirdListSelectionListener(dialog, first_list_selected_row, second_list_selected_row));
}
次に、次のようなThirdListSelectionListenerクラスを作成しました。
package eu.keep.gui.mainwindow.menubar.renderfile;
import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import eu.keep.characteriser.registry.Pathway;
public class ThirdListSelectionListener implements ListSelectionListener{
private ContentGenerated content;
public EmulatorList emulator_list;
private int first_list_selected_row;
private int second_list_selected_row;
private FirstList first_list;
private SecondList second_list;
private ThirdList third_list;
public ThirdListSelectionListener(MyDialog dialog, int first_list_selected_row, int second_list_selected_row){
this.content = dialog.content;
this.first_list_selected_row = first_list_selected_row;
this.second_list_selected_row = second_list_selected_row;
this.first_list = dialog.firstList;
this.second_list = dialog.secondList;
this.third_list = dialog.thirdList;
System.out.println("1. The first list row selected is "+this.first_list_selected_row);
System.out.println("2. The second list row selected is "+this.second_list_selected_row);
}
public void valueChanged(ListSelectionEvent e){
if (e.getValueIsAdjusting())
return;
Object source = e.getSource();
ListSelectionModel list = (ListSelectionModel)e.getSource();
if (list.isSelectionEmpty()) {
}else{
//int selected_row = list.getMinSelectionIndex();
try {
System.out.println("first: "+first_list_selected_row);
System.out.println("second: "+second_list_selected_row);
//System.out.println("third: "+selected_row);
// DO SOMETHING HERE
} catch (IOException e1) {
}
}
}
}
ここで問題があります。たとえば、最初のリストから2番目の行、2番目のリストから2番目の行、3番目のリストから2番目の行を最初に選択すると、予想どおり、次のメッセージが表示されます。
1. The first list row selected is 2
2. The second list row selected is 2
first: 2
second: 2
third: 2
ただし、2番目のリストから最初の行を選択してからすぐに3番目のリストから2番目の行を再度選択すると、次の出力が得られます。
1. The first list row selected is 2
2. The second list row selected is 1
first: 2
second: 2
third: 2
「秒:1」の代わりに「秒:2」を使い続けます。second_list_selected_rowはThirdListSelectionListenerコンストラクターで更新されると思いますが、valueChangedメソッドでは変更されません。誰かがこの問題の原因とそれを修正する方法を教えてもらえますか?前もって感謝します!!