GAlera consegui implementar a lista porém estou com algumas duvidas.
Vou postar o código primeiro.
Método do botão pesquisar:
[code]JButton btnPesquisarProf = new JButton(“Pesquisar”);
btnPesquisarProf.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProfessorNegocio profNegocio = new ProfessorNegocio();
Integer codProf;
String[] colunas = {“ID”,“Cód. Professor”,“Nome”,“CPF”,“Especialidade”,“Formação”,“Telefone”,“Endereço”};
if(edtCodProf.getText().equals("")){
codProf = 0;
}else{
codProf = Integer.parseInt(edtCodProf.getText());
}
try{
ArrayList<? extends Pessoa> listaProf = profNegocio.listar(
edtNomeProf.getText(), codProf,
edtCpfProf.getText());
ProfessorModel modelo = new ProfessorModel(listaProf, colunas);
System.out.println(modelo.getValueAt(0, 1));
gridPesqProf.setModel(modelo);
gridPesqProf.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}catch(Exception e1){
JOptionPane.showMessageDialog(null,"Ocorreu o seguinte erro ao listar os professores: "+ e1.getMessage(),
"Erro", JOptionPane.OK_OPTION);
e1.printStackTrace();
}
}
});[/code]
Meu Modelo para o JTable:
[code]public ProfessorModel(ArrayList dados, String[] colunas){
setLinhas(dados);
setColunas(colunas);
}
public String[] getColunas(){
return colunas;
}
public ArrayList getLinhas(){
return linhas;
}
public void setColunas(String[] strings){
colunas = strings;
}
public void setLinhas(ArrayList list){
linhas = list;
}
public int getColumnCount(){
return getColunas().length;
}
public int getRowCount(){
return getLinhas().size();
}
public Object getValueAt(int rowIndex, int columnIndex){
String[] linha = (String[]) getLinhas().get(rowIndex);
return linha[columnIndex];
}
}[/code]
Ao executar a tabela não é preenchida, no caso na camada de negocio a lista é verificada se está vazia, portanto a mesma não está. E ocorre este Excption:
java.lang.ClassCastException: br.com.framework.escola.entidades.pessoas.Professor cannot be cast to [Ljava.lang.String;
at br.com.framework.escola.visao.gui.PesquisaProfessores$ProfessorModel.getValueAt(PesquisaProfessores.java:174)
at br.com.framework.escola.visao.gui.PesquisaProfessores$2.actionPerformed(PesquisaProfessores.java:117)
referente a isto:
public Object getValueAt(int rowIndex, int columnIndex){
String[] linha = (String[]) getLinhas().get(rowIndex);
return linha[columnIndex];
}
Oque estou fazendo errado?
Obrigado