Vamos lá:
Eu construi um projeto e dentro dele tem,
Tabela.java (jFrame)
CampoCliente.java (Classe Java)
ExTableModel.java (Classe Java)
Arquivo ExTableModel.java:
[color=red]Esta dando erro! Não estou sabendo construir[/color]
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author CodeBlack
*/
public class ExTableModel extends AbstractTableModel {
private static final int COL_ID = 0;
private static final int COL_NOME = 1;
private List<CampoCliente> clientes;
public NomeTableModel (List<CampoCliente> clientes) {
this.clientes = new ArrayList<CampoCliente>(clientes);
}
public int getRowCount(){
return clientes.size();
}
public int getColumnCount(){
return 2;
}
public String getColumnName(int column){
if (column == COL_ID) return "ID";
if (column == COL_NOME) return "Nome";
return "";
}
public Object getValueAt(int row, int column) {
CampoCliente nome = clientes.get(row);
if (column == COL_ID) return nome.getIdcliente();
else if (column == COL_NOME) return nome.getNome();
return "";
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (columnIndex== COL_ID) nome.setIdcliente(aValue.toString());
else if (columnIndex== COL_NOME) nome.getNome().setNome(aValue.toString());
}
public Class getColumnClass(int columnIndex) {
return String.class;
}
boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
public CampoCliente get(int row) {
return clientes.get(row);
}
}
Arquivo CampoCliente.java:
public class CampoCliente {
private Integer idcliente;
private String nome;
/**
* @return the idcliente
*/
public Integer getIdcliente() {
return idcliente;
}
/**
* @param idcliente the idcliente to set
*/
public void setIdcliente(Integer idcliente) {
this.idcliente = idcliente;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
}
Arquivo Tabela.java:
public class Tabela extends javax.swing.JFrame {
public Tabela() {
initComponents();
tbClientes.setModel(new ExTableModel(/*Não sei o que tem que colocar aquiiiii!!!!!!*/));
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
tbClientes = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tbClientes.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(tbClientes);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(14, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Tabela().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tbClientes;
// End of variables declaration
}
Esse é o codigo!!!