[quote=danieldestro]for(int i=0; i<getRowCount(); i++ )
((DefautlTableModel)jTable.getModel()).removeRow(i);
[/quote]
Nem deu muito certo não…o meu eu fiz uma classe SimplesTableModel:
veja ela ae:[code]class SimplesTableModel extends AbstractTableModel{
private ArrayList ALTLinhas = null;
public String[] STGColuna = null;
public String[] getColunas() {return STGColuna;}
public ArrayList getLinhas() {return ALTLinhas;}
public void setColunas(String[] strings) {STGColuna = strings;}
public void setLinhas(ArrayList list) {ALTLinhas = list;}
public int getColumnCount() {return getColunas().length;}
public int getRowCount() {return getLinhas().size();}
public String[] getValor(int rowIndex) {
String [] STGLinhas = (String [])getLinhas().get(rowIndex);
return STGLinhas;
}
public String[] columnNames = new String[] {"Codigo","Razão Social","Nome Fantasia"};
public String getColumnName(int col) {
return columnNames[col].toString();
}
public Object getValueAt(int rowIndex, int columnIndex) {
String [] STGLinhas = (String [])getLinhas().get(rowIndex);
return STGLinhas[columnIndex];
}
public SimplesTableModel(ArrayList ALTDados1, String[] STGColuna, boolean [] BOOEdicao){
setLinhas(ALTDados1);
setColunas(STGColuna);
colsEdicao = BOOEdicao;
}
private boolean [] colsEdicao;
public boolean isCellEditable(int INTRow001, int INTCol001){
return colsEdicao[INTCol001];
}
public void setValueAt(Object OBJValues, int INTRow001, int INTCol001){
String [] STGLinhas = (String [])getLinhas().get(INTRow001);
STGLinhas[INTCol001] = (String)OBJValues;
fireTableCellUpdated(INTRow001,INTCol001);
}
public void addRow( String [] STGDadoLi){
JTBProdut.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getLinhas().add(STGDadoLi);
int INTLinhas = getLinhas().size()-1;
fireTableRowsInserted(INTLinhas,INTLinhas);
INTContLi++;
return;
}
public void removeRow(int row){
getLinhas().remove(row);
fireTableRowsDeleted(row,row);
INTContLi--;
}
}[/code]
Estou com problema com os nomes das colunas agora, em meu programa eu utilizo duas Jtable diferentes: então preciso pegar os nomes das colunas diferentes, mas não sei como fazer isso…
e o refresh mesmo: coloquei:for(int i=0; i < JTBCliente.getRowCount(); i++ ){
((SimplesTableModel)JTBCliente.getModel()).removeRow(i);}
Não remove certo…
To ficando loko já…
Ah o código no qual tenho minhas JTable são :[code]ArrayList ALTDados1 = new ArrayList();
String[] STGColuna = new String[] {“NumItem”,“CodItem”,“ValItem”};
boolean [] BOOEdicao = {true,true,true};
SimplesTableModel STMProdut = new SimplesTableModel(ALTDados1, STGColuna, BOOEdicao);
JTable JTBProdut = new JTable(STMProdut);
int INTContLi = 1, INTNumLin = 0;
ArrayList ALTDados2 = new ArrayList();
public String[] STGColuna2 = new String[] {"Código","Razão Social","Nome Fantasia"};
boolean [] BOOEdicao2 = {true,true,true};
SimplesTableModel STMCliente = new SimplesTableModel(ALTDados2, STGColuna2, BOOEdicao2);
JTable JTBCliente = new JTable(STMCliente);
int INTContLi2 = 1, INTNumLin2 = 0;[/code]
Valeu! 8)