Ai galera firmão !!!
Tenho um Model extendido de AbstractTableModel que trasforma ResultSets em JTable, o problema e que por exemplo eu adiciono dados no BD e eles não refletem no JTable ? como eu faço para atualizar o model da tabela ??? se quiserem ver o CODIGO FONTE segue abaixo:
não se espantem com Tbusuarios que e uma classe herdada de um mini-Framework que desenvolvi :roll: :
public class ListaUsuarios extends javax.swing.JInternalFrame {
public static class ModelUsuarios extends javax.swing.table.AbstractTableModel {
private String[] headers = {"Código","Nome","Modulo","Acesso"};
private Object[][] data;
private TbUsuarios tbusuarios;
public ModelUsuarios() {
int i = 0;
tbusuarios = new TbUsuarios();
try {
data = new Object[(tbusuarios.getRecorCount())][4];
do {
try{
data[i][0]=tbusuarios.getObject(tbusuarios.CODIGO);
data[i][1]=tbusuarios.getObject(tbusuarios.NOME);
data[i][2]=(Object)getModulo(tbusuarios.getInt(tbusuarios.MODULO));
data[i][3]=(Object)getAcesso(tbusuarios.getInt(tbusuarios.ACESSO));
i++;
}catch(java.lang.ArrayIndexOutOfBoundsException e){
return;
}
}while(tbusuarios.next());
}catch(java.sql.SQLException e1){Assistente.geInstance().msgError(e1.toString(), null);}
}
/** Returns the number of columns in the model. A
* <code>JTable</code> uses this method to determine how many columns it
* should create and display by default.
*
* @return the number of columns in the model
* @see #getRowCount
*
*/
public int getColumnCount() {
try {
return data[0].length;
}catch(java.lang.NullPointerException e){return 0;}
}
/** Returns the number of rows in the model. A
* <code>JTable</code> uses this method to determine how many rows it
* should display. This method should be quick, as it
* is called frequently during rendering.
*
* @return the number of rows in the model
* @see #getColumnCount
*
*/
public int getRowCount() {
try {
return data.length;
}catch(java.lang.NullPointerException e){return 0;}
}
/** Returns the value for the cell at <code>columnIndex</code> and
* <code>rowIndex</code>.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*
*/
public Object getValueAt(int rowIndex, int columnIndex) {
try {
return data[rowIndex][columnIndex];
}catch(java.lang.NullPointerException e){return null;}
}
public String getColumnName(int column) {
return headers[column];
}
public Class getColumnClass(int column) {
try {
return data[0][column].getClass();
}catch(java.lang.NullPointerException e){return null;}
}
private String getModulo(int index) {
String[] items = {"Todos","Compras","Licitação","Almoxarifado"};
return items[index];
}
private String getAcesso(int index) {
String[] items = {"Completo","Depende de Senha","Somente Leitura","Almoxarifado","Customizado"};
return items[index];
}
}
falow t+