助けが得られることを願っています。一般的な質問として尋ねます。
を使用しJList
てJList
いますが、 (value,text) がないため (テキストを表示して、コードで値を使用できます)。このリークのためList
、オブジェクト (myList)を作成しますJList
。に追加するすべてのアイテムを に追加するJList
ためmyList
、同じインデックスに 2 つのオブジェクト (JList と mylist) に同じ情報が含まれます。JList.getselectedindex()
メソッドを使用してインデックスを取得し、それを使用して情報を追加しmyList
ます...
問題: 値を選択すると、次の値がmyList
最初の値で上書きされます!!! この問題は既知ですか?
mod_mp = new ModelMAPPING(); objects cotain values that ot exist in jList
msgF.setTo(incom.userID);/////// set parter!
if(isExCon==-1) {
// not exist
mod_mp.to = incom.userID; // incom is object that incom from another program
mod_mp.SetCovFile(incom.userID+".html");
mod_mp.ConvName = incom.getBody();
boolean added= model_list.add(mod_mp); // add to mylist
if(added) System.out.println(mod_mp._Hfile + " added");
model.addElement(mod_mp.ConvName);// add to Jlist by model
HestoryFile(Htmlhead+tohis,mod_mp._Hfile);//create _Hfile and write to it:"tohis" string.
} else { //exist@
// note isExcon return the index if exist else -1
model_list.get(isExCon).ConvName=incom.getBody();
mod_mp.SetCovFile(model_list.get(isExCon)._Hfile);
HestoryFile(tohis, model_list.get(isExCon)._Hfile);
}//end else
ここでファイルが存在する場合、新しいテキストを更新しJList
て現在のファイルを設定します
の選択JList
は次のとおりです。
msgF.setTo (model_list.get(jList2.getSelectedIndex()).to); // set that we will send To...
mod_mp.SetCovFile(model_list.get(jList2.getSelectedIndex())._Hfile);//set the file
jLabel5.setText( bringFromFile(mod_mp._Hfile));//tell the label to read that file
それは正常に動作しますが、2 つのアイテムがあるJList
場合、いずれかを選択すると、もう一方が上書きされます!!!