How to refresh data in JTable I am using TableModel

后端 未结 6 1149
情歌与酒
情歌与酒 2020-11-30 11:59

Hi,

I have created my TableModel and want to refresh JTable once I added a new row. What should be added to the listener to \"refresh\" JTable?

publ         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 12:40

    Your class MyTableModel implements TableModel, but it has no event handling mechanism to connect the model to the view. Instead extend AbstractTableModel, as shown here and here. AbstractTableModel provides the fireTable* methods needed for this.

    public void setValueAt(Object value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
    

提交回复
热议问题