Tenho uma classe ModeloTabela e tenho um metodo para preencher a tabela, gostaria de alterar a cor da linha da tabela se o valor for menor que X.
ModeloTabela
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
/**
*
* @author Paulo Henrique
*/
public class ModeloTabela extends AbstractTableModel {
private ArrayList linhas = null;
private String[] colunas = null;
public ModeloTabela(ArrayList lin, String[] col){
setLinhas(lin);
setColunas(col);
}
public ArrayList getLinhas(){
return linhas;
}
public void setLinhas(ArrayList dados){
linhas = dados;
}
public String[] getColunas(){
return colunas;
}
public void setColunas(String[] nomes){
colunas=nomes;
}
public int getColumnCount(){
return colunas.length;
}
public int getRowCount(){
return linhas.size();
}
public String getColumnName(int numCol){
return colunas[numCol];
}
public Object getValueAt(int numLin, int numCol){
Object[] linha = (Object[])getLinhas().get(numLin);
return linha[numCol];
}
}
Aqui vem o codigo do PreencherTabela
public void preencherTabelaMeta(String SQL){
ArrayList dados = new ArrayList();
String[] Colunas = new String[]{"ID","Data de Lançamento","Valor Total","Funcionario"};
conexao.conexao();
conexao.executaSQL(SQL);
try {
conexao.rs.first();
do{
dados.add(new Object[]{conexao.rs.getInt("id_venda"),conexao.rs.getString("data_venda"),conexao.rs.getFloat("valor_venda"),conexao.rs.getString("nome")});
}while(conexao.rs.next());
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro ao preencher Tabela!\n"+ex);
}
ModeloTabela modelo = new ModeloTabela(dados, Colunas);
tabelaMeta.setModel(modelo);
tabelaMeta.getColumnModel().getColumn(0).setPreferredWidth(60);
tabelaMeta.getColumnModel().getColumn(0).setResizable(true);
tabelaMeta.getColumnModel().getColumn(1).setPreferredWidth(200);
tabelaMeta.getColumnModel().getColumn(1).setResizable(false);
tabelaMeta.getColumnModel().getColumn(2).setPreferredWidth(120);
tabelaMeta.getColumnModel().getColumn(2).setResizable(false);
tabelaMeta.getColumnModel().getColumn(3).setPreferredWidth(200);
tabelaMeta.getColumnModel().getColumn(3).setResizable(false);
tabelaMeta.getTableHeader().setReorderingAllowed(false);
tabelaMeta.setAutoResizeMode(tabelaMeta.AUTO_RESIZE_OFF);
tabelaMeta.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}