Problema com DefaultTableModel

1 resposta
Sombriks

ok, ocorre que numa tela q estou fazendo dentro do Netbeans 5.0 ando entrentando uma questão curiosa; vide código e comentários:

//... pacote, imports, etc.

 public CrUDeDataGrid(PersistenceSide ps,VectorWarper vw) {
        this.vw=vw;
        this.ps=ps;
        dtm=new DefaultTableModel();
        initComponents();
        jTable1.setModel(dtm);
    }
    public void select(VO vo){
        //Primeiro recuperamos os dados...
        List<List>res=ps.getData(vo);
        //Em seguida limpamos o TableModel, nunca se sabe...
        for(int i=0;i<dtm.getRowCount();i++)dtm.removeRow(i);
        //Pegamos aqui a página selecionada...
        List><VO> page=res.get(selectedPage);
        //e agora adicionamos as novas linhas...
        for(VO v : page)dtm.addRow(vw.warpVector(v));
        //TODO - Continuar isso aqui; avaliar se esse trecho de código realmente fica no componente.
        //jTable1.setModel(dtm);
    }
    public void insert(VO vo) {
        ps.insert(vo);
        select(null);
    }

    public void update(VO vo) {
        ps.update(vo);
        select(null);
    }

    public void delete(VO vo) {
        ps.delete(vo);
        select(null);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null}
            },
            new String [] {
                "Title 1", "Title 2"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("P\u00e1gina Anterior");

        jButton2.setText("Pr\u00f3xima P\u00e1gina");
//... e por aí vai.

no trecho acima eu crio um DefaultTableModel que eu passo como modelo do meu painel. em seguida eu o populo com vetores que, teoricamente, deveriam ser as linhas dele. Todavia estas linhas jamais aparecem; por que?

ficaira feliz em receber alguma luz aqui, e se eu mesmo encontrar uma resposta voltarei aqui pra esclarecer como foi, :smiley:

até!

1 Resposta

Sombriks

Senhores, felizmente encontrei a resposta: bastou que fosse adicionado o nome das colunas ao DefaultTableModel e a coisa toda funcionou, :smiley:

//...
    /** Creates new form CrUDeDataGrid */
    public CrUDeDataGrid(PersistenceSide ps,VectorWarper vw,String[]colunas) {
        this.vw=vw;
        this.ps=ps;
        dtm=new DefaultTableModel(colunas,0);//Aqui, usei esse construtor!
        initComponents();
        jTable1.setModel(dtm);
    }
//...

até!

Criado 14 de maio de 2006
Ultima resposta 14 de mai. de 2006
Respostas 1
Participantes 1