Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to update Jtable propertly using a class extending AbstractTableModel? without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
This class extends AbstractTableModel
. It has an ArrayList arr but I don’t know how to use the fire methods.
public void adiciona(Entidad e) { if(DEBUG) System.out.println( " tamaño: "+tamaño()+" columas: "+getColumnCount()+"" + Arrays.deepToString(columnNames) ); //size 6 arr.add(e);//adds if(DEBUG) System.out.println( " tamaño: "+tamaño()+" columas: "+getColumnCount()+"" + Arrays.deepToString(columnNames) ); //size 7 //setNumRows( getRowCount() - 1 ); //System.out.println( "hola"); fireTableStructureChanged();//BOOOOm EXEPTION NULL POINTER ARRAY fireTableDataChanged(); System.out.println( "hola"); }
i am checking the java source on how java has the default table model … what would be the equivalent for
private void justifyRows(int from, int to) { arr.setSize(getRowCount()); for (int i = from; i < to; i++) { if (dataVector.elementAt(i) == null) { dataVector.setElementAt(new Vector(), i); } ((Vector)dataVector.elementAt(i)).setSize(getColumnCount()); } }
in an ArrayList
Answer
It has an ArrayList
Then use a custom TableModel that supports an ArrayList containing any custom Object.
For example you could use the Row Table Model. It provides a custom TableModel that stores custom Objects in an ArrayList. You will need to implement the getValueAt() and setValueAt() methods as they related to your custom Object. The JButtonTableModel
example shows you how this can be done.
We are here to answer your question about How to update Jtable propertly using a class extending AbstractTableModel? - If you find the proper solution, please don't forgot to share this with your team members.