如何为 Swing 中的 JTable 提供分页支持?
我在 Swing Java 中创建了一个 GUI,其中使用了 JTable。现在我想通过使用分页在其中显示下一页信息。我该怎么做呢?
I have created one GUI in Swing Java in which I have used JTable.Now I want to display next page information into it by using pagination. How should I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
实现此目的的另一个选项是使用无滚动条的滚动窗格和几个导航按钮来实现控制。已添加的按钮是原型的普通
JButton
。下面添加了一个快速原型。它做出了几个假设,其中之一是表模型拥有其所有数据。可以做一些工作来确保行在导航时最终齐平于视图顶部。
替代文本 http://img7.imageshack.us/img7/4205/picture4qv.png< /a>
Another option to implement this is to use a scrollbar-less scrollpane and a couple nav buttons to effect the control. The buttons that have been added are normal
JButton
s for the prototype.A quick prototype is added below. It makes a couple assumptions, one of which is that the table model has all of its data. Work could be done to ensure that rows end up flush at the top of the view upon navigation.
alt text http://img7.imageshack.us/img7/4205/picture4qv.png
Swing JTable 中的分页 看起来是一篇不错的文章。
以下是摘录:
Paging in a Swing JTable looks like a nice article.
Here is an excerpt:
您可以尝试使用 2 个查询,第一个查询是计算数据库中的总行数,第二个查询是针对真实数据:) 对于 UI 端,您可以这样尝试:
在服务层中,你只需要使用像这样的限制功能:
或者你可以在github上分叉我 Swing 上的项目页表分页 :)
You can try with 2 query, first query is to count total rows in DB and second query is for the real data :) And for the UI side, you can try like this:
And in service layer, you just need use limit function like this :
Or you can fork me on github at Project Page Table Paging on Swing :)
我写了一个Java分页工具dataj。它使用 JQuery dataTables 插件分页元数据来构建结果页面。
我还为 Java Swing 添加了一些客户端类,其中包括一个 TableRowSorter,它调用(服务器端)排序而不是在表模型内排序。
欢迎下载,如有任何疑问请联系我。它遵循 Apache 2 许可证。
I have written a Java pagination tool dataj. It uses JQuery dataTables plug-in pagination metadata to build up the result page.
I have also added some client classes for Java Swing including a TableRowSorter that calls the (server side) sorting instead of sorting inside the table model.
Feel free to download it and contact me if you have any questions. It's under Apache 2 license.
或者,您可以使用
QuickTable
项目。屏幕截图
以下是正在运行的
DBTable
组件:DBTable
组件嵌入在传统的JFrame
中。示例代码
以下示例代码生成上一个屏幕截图中所示的窗口:
资源和依赖项
test.csv
H2
参考文献
Alternatively, you can make use of the
QuickTable
project.Screenshot
Here is the
DBTable
component in action:The
DBTable
component is embedded in a traditionnalJFrame
.Sample code
The following sample code produces the window shown in the previous screenshot:
Resources and dependencies
test.csv
H2
References