JTable 更新后不显示结果?
从数据库获取结果后,我在运行时创建一个表。我的申请流程是这样的。
- 初始化一个空的 JScrollPane();
JScrollPane tableScroll = new JScrollPane();
- 从数据库中获取结果;
- 使用以下方法将结果更新到 JTable 并将 JTable 添加到 JScrollPane:
代码:
private void setResultTable(Vector documents, Vector header) {
TableModel model = new DefaultTableModel(documents, header);
documentTable.setModel(model);
tableScroll.add(documentTable);
tableScroll.repaint();
}
我的问题是调用 setResultTable 后结果没有出现在表中。请帮我解决这个问题。提前致谢 !!!
I am creating a table at run time after fetching the result from the database. The flow of my application is like this.
- Initializing a empty JScrollPane();
JScrollPane tableScroll = new JScrollPane();
- Fetching result from the database;
- Updating result to JTable and adding JTable to JScrollPane using following method:
Code:
private void setResultTable(Vector documents, Vector header) {
TableModel model = new DefaultTableModel(documents, header);
documentTable.setModel(model);
tableScroll.add(documentTable);
tableScroll.repaint();
}
my problem is that after calling setResultTable the result are not appearing in the table. Please help me with that. Thanks in advance !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎将 JTable 直接添加到 JScrollPane 中。如果是这样,这是不正确的,您需要更改它,以便实际上将表添加到滚动窗格的视口中:
执行此操作后无需重新绘制 JScrollPane。
例如:
如果这没有帮助,您还需要准确地告诉我们发生了什么,您看到了什么,如果可能的话,向我们提供一个小型可编译的可运行程序来演示您的问题,一个 SSCCE
You appear to be adding the JTable directly to the JScrollPane. If so this isn't correct and you'll want to change this so that you're actually adding the table to the scroll pane's viewport:
There is no need to repaint the JScrollPane after doing this.
For example:
If this doesn't help, you'll want to also tell us exactly what happens, what you see, and if possible supply us with a small compilable runnable program that demonstrates your problem, an SSCCE