JTable 和 TableModel 之间
现在我很困惑...
JTable 是 swing API 的一部分,因此它处理我们查看表格的方式 用 JTable table = new JTable() 表示;
然而,要使用数据库进行操作,它需要另一个类,它可以是从 AbstractTableModel 或 DefaultTableModel 扩展而来的。 该如何表述呢?
第二:
JTable(Object[][] rowData, Object[] columnNames)
JTable(Vector rowData, Vector columnNames)
这是我从sun网站获得的,如何或可能将其放入代码中?
据我了解,从任一类扩展的类如何处理数据处理。这是否意味着它如何在 JTable 的视图中以及模型中打印?
好吧,如果有关于这部分的任何阅读,请指出我可以在哪里阅读。
提前致谢
Now I get confused...
JTable is a part of a swing API so it's handling with how we view the table
stated with JTable table = new JTable();
However to do things with database it needs another class, either it's extended from AbstractTableModel or DefaultTableModel.
How to state this ?
Second :
JTable(Object[][] rowData, Object[] columnNames)
JTable(Vector rowData, Vector columnNames)
This is what I get from sun website, how or maybe where to put that in the code ?
As far as I read how data handled is dealt on by the class that extends from either the class. Does it mean how it's printed in view on JTable also in the Model ?
Well, if there's any reading on this part, please point on where I can read this.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道我是否完全理解你的问题。您是否询问如何从 JDBC 结果集创建 TableModel?如果是这样,这里有一个很好的技术:
http:// /technojeeves.com/joomla/index.php/free/59-resultset-to-tablemodel
这会将所有数据读取到内存中。如果您的查询非常大,并且您的 JDBC 驱动程序支持任意滚动游标,那么您可以创建由 ResultSet 本身支持的 TableModel 接口的实现,这应该可以防止您的应用程序因大量结果而耗尽内存。这有点复杂,但在这里进行了演示:
http:// www.java2s.com/Code/Java/Swing-JFC/ResultSetTable.htm
I don't know if I completely understand your question. Are you asking how to create TableModel from a JDBC ResultSet? If so, there is nice technique for doing that here:
http://technojeeves.com/joomla/index.php/free/59-resultset-to-tablemodel
This reads all of the data into memory. If your query is very large, and if your JDBC driver supports arbitrary scrolling cursors, then you could create an implementation of the TableModel interface that is backed by the ResultSet itself, which should prevent your application from running out of memory with large results. That is a little more complex, but it is demonstrated here:
http://www.java2s.com/Code/Java/Swing-JFC/ResultSetTable.htm