我想在另一個JFrame中按下按鈕時刷新JList。從另一個JFrame中刷新Jlist
所以我有一個JFrame GuiBoss管理員工(添加,刪除,更新)。當我按下按鈕添加,另一個Jframe打開,在我創建一個新的員工。
//打開「add_form」,在其中給出有關新員工的詳細信息。
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
GuiBoss gb = new GuiBoss(contrb,boss);
Add_form af = new Add_form(gb,contrb,boss);
af.setVisible(true);
}
//刷新列表並添加新員工。
public void refresh(Employee e){
System.out.println("I reach this point!");
//if i print e.getName() it works, printing the right name that i give in the "add_form"
listModel.addElement(e);
//listModel.clear(); //don't work either.
}
我的問題是,當我從GuiBoss框架,消息提交有關新員工我調用該函數刷新(員工E)的細節(「我到了這個地步!」)在控制檯上顯示出來,listModel的大小會改變,但它不會刷新的列表。 另外我必須說,我正確地爲列表設置模型。
//採取從主框架( 「GuiBoss」)從形式和呼叫刷新(員工E)數據
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
//String Id = txtID.getText();
String UserName = txtName.getText();
txtHour.setVisible(false);
boolean b = false;
if(rbtnYes.isSelected() == true){
b = true;
}
if(rbtnNo.isSelected() == true){
b = false;
}
if(rbtnYes.isSelected()==false && rbtnNo.isSelected() == false){
System.out.println("Select the presence!");
}
else{
txtOra.setVisible(true);
String Hour = txtHour.getText();
e = new Employee(UserName,b,Hour,boss); //boss i get from main frame when i start this add new employee form
contrb.addEmployee(e);
gb.refresh(e); //gb is of type GuiBoss were i have the function that does
// the refresh
}
}
請讓我知道如果u有任何ideeas.Thanks。
*「當我在另一個JFrame中按下一個按鈕,」 *應該只有一個!請參閱[使用多個JFrames,好/壞實踐?](http://stackoverflow.com/a/9554657/418556) – 2013-04-11 22:31:07