3
I have a form for payment of installments, and this form has a table where I show both the installments paid and those that should still be paid.
To popular this JTable
, I make a query in the database and bring the necessary information.
public void preencherParcelas(String SQL) {
ArrayList dados = new ArrayList();
String[] colunas = new String[]{"Data Pagamento", "Valor Parcela", "Status Pagamento"};
conecta.conexao();
conecta.executaSQL(SQL);
String status;
try {
conecta.rs.first();
dataVenda = conecta.rs.getString("data_venda");
idParcelamento = conecta.rs.getInt("id_parcelamento");
do {
if (conecta.rs.getInt("status_pagamento") == 0) {
status = "PAGAMENTO PENDENTE";
} else {
status = "PAGAMENTO EFETUADO";
}
dados.add(new Object[]{conecta.rs.getString("data_pagamento"), "R$ " + conecta.rs.getString("valor_parcelas"), status});
} while (conecta.rs.next());
} catch (SQLException ex) {
JOptionPane.showMessageDialog(rootPane, "ERRO AO LOCALIZAR PARCELAS" + ex);
}
ModeloTabela modelo = new ModeloTabela(dados, colunas);
jTableInformaVencimentos.setModel(modelo);
jTableInformaVencimentos.getColumnModel().getColumn(0).setPreferredWidth(150);
jTableInformaVencimentos.getColumnModel().getColumn(0).setResizable(false);
jTableInformaVencimentos.setModel(modelo);
jTableInformaVencimentos.getColumnModel().getColumn(1).setPreferredWidth(150);
jTableInformaVencimentos.getColumnModel().getColumn(1).setResizable(false);
jTableInformaVencimentos.setModel(modelo);
jTableInformaVencimentos.getColumnModel().getColumn(2).setPreferredWidth(150);
jTableInformaVencimentos.getColumnModel().getColumn(2).setResizable(false);
jTableInformaVencimentos.getTableHeader().setReorderingAllowed(false);
jTableInformaVencimentos.setAutoResizeMode(jTableInformaVencimentos.AUTO_RESIZE_ALL_COLUMNS);
jTableInformaVencimentos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
conecta.desconecta();
Model used in the Table
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(){
//retorna a quantidade de colunas(conta a quantidade e retorna)
return colunas.length;
}
public int getRowCount(){
//retorna o tamanho do array(quantos letras tem)
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];
}
}
I’d like to know when a "PAYMENT MADE" that one String stay in preferred red color. How can I do this?
String? You mean ne table cell phone?
– user28595
Whatever makes it easier... If it’s just the same String and insert it already with the new color.
– Valdecir
It’s not the same thing to colorize string and colorize cell. You need to define what you really want so that the answer matches the problem.
– user28595
I want to color the string and insert it in jTable.
– Valdecir
Only the text.
– Valdecir
Pay column only or the whole row text?
– user28595
Just the word pay.
– Valdecir
Add how you’re filling in jtable. If you’re using a model or Renderer, add them to the question as well.
– user28595
It is up in question, I make a select in the database and add in the table.
– Valdecir
There is no code that shows how jtable is being populated. Add to question how you are populating jtable.
– user28595
Add the getcolumnclass and getvalueat method of your modelotabela class as well.
– user28595
The model I’m wearing is this.
– Valdecir