3

I need to build a table from SQL select result set. I want to add some paging functionality to the table because the result set can be very large. There was many discussions how to do the paging at the SQL level. But how to implement the paging at the GUI level? I have two ideas:

  1. Do the paging in a web UI style - for example google search result paging;
  2. "Excel style" - the scroll pane where the table resides expands as user scrolls down.

The second one looks nicer but complex to implement. When to do SQL select for a next chunk of data so that a user haven't wait for it. There should be some "read ahead" logic? What will happen if user scrolls quite quickly? What to do with rows that aren't visible any more to have constant memory usage? Maybe there is already such a table component or good examples? Or maybe this good looking table functionality is unworthy of efforts to implement it?

4

2 回答 2

1

您可以直接在 TableModel 中进行所有操作,无需更改 UI 中的某些内容(您可能会在 UI 中显示某些内容 - 一种状态 - 但您不需要更改 JTable 呈现自身的方式)。

只需实现一个 JDBCTableModel ,它将具有:

  • 计算结果并将此值作为 getRowCount() 返回。
  • 有一个后台线程,它将页面 X(行 X 到行 X + page_size)带入内存
  • 如果视图(JTable)请求不存在的行(页面未加载),则在左上角或右上角的某处显示消息“正在加载数据...”并返回空单元格。

分页对 Swing 应用程序没有意义,它是在当前花哨的 AJAX 库可以实现表格滚动之前发明的(参见http://www.ext-livegrid.com/)。

于 2009-06-01T16:05:48.247 回答
0

为 AJAX 库构建分页表的人显然对此想了很多,所以如果你找不到已经构建的东西,你也许可以向他们学习。由于您使用的是 Java,请注意您可以找到用 Java 编写的用于 GWT 的分页表。请参阅这些 SO 线程:

GWT 分页小部件

GWT 中的最佳分页表实现

您实现的想法(以及大部分代码)可以在提到的开源项目中找到。

于 2009-06-02T03:42:53.990 回答