java - 使用 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);
解决方案
表头未显示
frmStudentCrud.getContentPane().add(table_1);
仅当您将表格添加到滚动窗格并将滚动窗格添加到框架时,才会显示标题。
您的代码应该是:
//frmStudentCrud.getContentPane().add(table_1);
JScrollPane scrollPane = new JScrollPane( table_1 );
frmStudentCrud.getContentPane().add( scrollPane );
推荐阅读
- javascript - 如何编辑JS日期和时间自动更新?
- linux - 无法从 Docker 容器访问网络
- arrays - 如何以选定的维度对数组进行切片?
- excel - 用于查看绘图上不同数据的 MS Excel 下拉菜单
- python-sphinx - 可以将 Sphinx 的 extlinks 扩展配置为显示 url 吗?
- azure - 当容器之一终止时停止容器实例组
- node.js - 何时将用户输入写入数据库?
- c++ - STM32 引脚 B0 用作输入,但 B1 不用作
- javascript - 在 React 中克隆整个状态对象会导致副作用吗?
- inheritance - Rust 中的方法覆盖替代方案