在JFrame之间切换后,JTable不会更新

时间:2018-04-13 18:26:40

标签: java swing jframe jtable

我在两个JFrame窗口之间切换,但是当我切换时,我正在尝试更新JTable,因为一个框架是添加员工而另一个是显示一个表格员工。因此,在您添加员工并返回原始框架后,它应该更新表格。问题是更新表的方法没有运行。

以下是包含表格的框架的代码:

public class employeeUI extends javax.swing.JFrame {

ArrayList<employeeClass> employeeList = new ArrayList<employeeClass>();

/**
 * Creates new form employeeUI
 */
public employeeUI() {
    initComponents();
    readfromFile();
    populateTable();
    getContentPane().setBackground(new Color(23, 76, 79));
}

public void populateTable() {
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    Object rowData[] = new Object[7];
    for (int i = 0; i < employeeList.size(); i++) {
        rowData[0] = employeeList.get(i).employeeID;
        rowData[1] = employeeList.get(i).employeeName;
        rowData[2] = employeeList.get(i).employeeEmail;
        rowData[3] = employeeList.get(i).employeeAddress;
        rowData[4] = employeeList.get(i).employeeTitle;
        rowData[5] = "$" + employeeList.get(i).employeeSalary;
        rowData[6] = employeeList.get(i).employeeHire;
        model.addRow(rowData);
    }
}

以下是展示问题的视频:https://streamable.com/yscze

0 个答案:

没有答案