A table header is not shown using Eclipse. How to solve the problem? Only data coming from the database successfully. So I attached below what I tried.
This is the code that I used to display the data from the database:
void table_load() {
try {
pst = con.prepareStatement("select * from registation");
rs = pst.executeQuery();
table_1.setModel(DbUtils.resultSetToTableModel(rs));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
table_1 = new JTable();
table_1.setBounds(448, 62, 383, 296);
frmStudentCrud.getContentPane().add(table_1);
table header is not shown
frmStudentCrud.getContentPane().add(table_1);
The header is only shown when you add the table to a scroll pane and add the scroll pane to the frame.
Your code should be:
//frmStudentCrud.getContentPane().add(table_1);
JScrollPane scrollPane = new JScrollPane( table_1 );
frmStudentCrud.getContentPane().add( scrollPane );