首页 > 解决方案 > 使用 Eclipse 未显示表头

问题描述

使用 Eclipse 不显示表头。如何解决问题?只有来自数据库的数据成功。所以我附上了我尝试过的内容。 在此处输入图像描述

这是我用来显示数据库数据的代码:

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);

标签: javaswingjtable

解决方案


表头未显示

frmStudentCrud.getContentPane().add(table_1);

仅当您将表格添加到滚动窗格并将滚动窗格添加到框架时,才会显示标题。

您的代码应该是:

//frmStudentCrud.getContentPane().add(table_1);
JScrollPane scrollPane = new JScrollPane( table_1 );
frmStudentCrud.getContentPane().add( scrollPane );

推荐阅读