No column name in jTable

Asked

Viewed 89 times

1

I created a Jscrollpane and in it a jTable, all this inside a Jinternalframe, but when I run my Jframe and open this Jinternalframe, it only shows the data in rows that are in my database, but does not show up the names of the columns. Code of Jinternalframe

public class Listar extends javax.swing.JDialog {

private AnnotationResolver resolver;
private ObjectTableModel otm;
private UsuarioDao dao;
/**
 * Creates new form Listar
 * @param parent
 * @param modal
 */
public Listar(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    resolver = new AnnotationResolver(modelo.Usuario.class);
    otm = new ObjectTableModel(resolver, "nome,sobrenome,email,departamento");
    try {
        dao = new UsuarioDao();
        otm.setData(dao.listarTodasAsPessoaList());
        jTable1.setModel(otm);
    } catch (SQLException ex) {
        Logger.getLogger(Listar.class.getName()).log(Level.SEVERE, null, ex);
    }

}


private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();

    jTable1.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(jTable1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(43, 43, 43)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(75, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(26, 26, 26)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(102, Short.MAX_VALUE))
    );

    pack();
} private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTable jTable1;}
  • Add a code that is a [mcve] so that it may be possible to test you, and your ObjectTableModel

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.