bom dia galera… estou com uma pequena duvida…
tenho uma tela que traz informações do cliente, mas as colunas estão ficando apertadas…
como poderia resolver isso???
utilizo um metodo dentro do DAO para listar todos os cliente que é esse!
public static Cliente populateCliente(ResultSet rs) throws SQLException {
Cliente toReturn = new Cliente();
toReturn.setCodigo(rs.getInt("codigo"));
toReturn.setNome(rs.getString("Nome"));
toReturn.setCpf(rs.getString("CPF"));
toReturn.setRg(rs.getString("RG"));
toReturn.setData_nascimento(rs.getDate("data_nascimento"));
toReturn.setTelefone_casa(rs.getString("telefone_casa"));
toReturn.setTelefone_celular(rs.getString("telefone_celular"));
toReturn.setTelefone_outro(rs.getString("telefone_outro"));
toReturn.setEmail(rs.getString("email"));
toReturn.setCep(rs.getString("cep"));
toReturn.setLogradouro(rs.getString("logradouro"));
toReturn.setNumero(rs.getInt("numero"));
toReturn.setBairro(rs.getString("bairro"));
toReturn.setComplemento(rs.getString("complemento"));
toReturn.setCidade(rs.getString("cidade"));
toReturn.setUf(rs.getString("uf"));
return toReturn;
}
e dentro do formulário eu chamo ele assim
public void carregartabela() {
try{
clientes = dao.gettodosClientes();
MyTableModel tableModel = new MyTableModel(Cliente.class, clientes, tabelaCliente);
tabelaCliente.setModel(tableModel);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Erro ao Carregar");
}
mas utilizo uma classe que chama mytable
[code]
public class MyTableModel extends DefaultTableModel {
private static final long serialVersionUID = 1L;
private final List entitysToList;
private final Class entityClassToList;
private List<Method> fieldToData = new ArrayList<Method>();
private final JTable tableToControl;
/**
* Construtor padrão
*
* @author Dyego Souza do Carmo
* @version 1.0,
*/
public MyTableModel(Class entityClassToList, List entitysToList,JTable tableToControl) {
super();
this.entitysToList = entitysToList;
this.entityClassToList = entityClassToList;
this.tableToControl = tableToControl;
try {
startAddTheColumns();
startAddValues();
} catch (Exception ex) {
Logger.getLogger(MyTableModel.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void startAddTheColumns() throws NoSuchMethodException, InstantiationException, IllegalAccessException {
// Here is The Reference Class !
// Reflection is the man !!!!! (or the method ?)
for (Field field : entityClassToList.getDeclaredFields()) {
SwingColumn theAnnotation = field.getAnnotation(SwingColumn.class);
if (theAnnotation != null) {
// Yes , the column is annotated , but and the next ?
addColumn(theAnnotation.description());
//tableToControl.getColumnModel().getColumn(getColumnCount()-1).setCellRenderer(theAnnotation.renderer().newInstance());
String methodName = "get" + field.getName().toUpperCase().charAt(0) + field.getName().substring(1);
fieldToData.add(entityClassToList.getDeclaredMethod(methodName));
}
}
}
private void startAddValues() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
// Manipulates Only the DATA fields
for (Object entity : entitysToList) {
List<Object> valuesToAdd = new ArrayList<Object>();
for (Method method : fieldToData) {
valuesToAdd.add(method.invoke(entity));
}
// Here we add the values in the MODEL !
addRow(valuesToAdd.toArray());
}
}
}[/code]
e com essa classe eu preciso apenas fazer as anotações assim em cada classe
@SwingColumn(description="Código",colorOfBackgound="")// essa seria a anotação para criar as coluna
private Integer codigo;
@Column
@SwingColumn(description="nome",colorOfBackgound="")//essa seria a anotação para criar as coluna
private Integer codigo;
private String nome;
@Column
@SwingColumn(description="CPF",colorOfBackgound="")//essa seria a anotação para criar as coluna
private Integer codigo;
private String cpf;