JTable Insert row and refresh

Posted by user269723 on Stack Overflow See other posts from Stack Overflow or by user269723
Published on 2010-05-29T18:13:57Z Indexed on 2010/05/29 18:22 UTC
Read the original article Hit count: 299

Filed under:

Hi All, I am trying to create simple application where JTable gets updated and refreshed after data is changed.Structure is as follows. 1)Class Main which contains JFrame,JTable details. 2)SampleTableModel class which extends AbstractTableModel.I am overriding most of the methods.`import javax.swing.table.; import javax.swing.event.; import java.util.*;

public class SampleTableModel extends AbstractTableModel {

public SampleTableModel(){
   // this.addTableModelListener(
}

String[] columnNames = {"A","B","C","D","E"};
int[][] data = {{1,2,3,4,5},{5,6,7,8,9},{12,13,14,15,16}};

Vector dataVector = new Vector();

public Object getValueAt(int rowIndex,int columnIndex) {
           return data[rowIndex][columnIndex];
       }
public int getColumnCount(){
    return 5;
}
public int getRowCount(){
    return 3;
}
public String getColumnName(int columnIndex){
    return columnNames[columnIndex];
}
public void setValueAt(Object value,int row,int column){
    data[row][column] =99;


}
public  void notifyTable(AEMessage message){
    /*
     * This method will be called from another class to update JTable.
     * */
     data[0][1]=999;
     data[0][2]=8838;
     data[1][1]=8883;
     fireTableRowsUpdated(0,3);

}

} ` As you can see, notifyTable will be called from another class(which is actually a thread-which calls this method frequently) Problem is I don't see data being changed in JTable.I see only the initialized data. In the Main class- I am setting like this-

RVJDataTable.setModel(new SampleTableModel());

© Stack Overflow or respective owner

Related posts about java