JTable 列跨越
我正在尝试制作一个具有可用列跨度的 JTable
。 具体来说,我希望将一个 JTable
嵌套在另一个 JTable
中,当用户单击查看嵌套表时,它应该展开以下推下面的行并填充空的空间。 这与您在 MS Access 中看到的类似,您可以在其中嵌套表,单击行上的展开按钮将显示嵌套表中的相应条目。
如果有人知道使用 JTable
执行列跨度的方法,您能给我指出正确的方向吗? 或者,如果您知道其他方法可以做到这一点,我愿意接受建议。 该应用程序是使用 Swing 构建的。 表中的元素(无论是高级元素还是低级元素)都必须在任何解决方案中都是可编辑的。 使用嵌套的 JTable 不会成为问题,任何其他解决方案也必须考虑到这一点。
I am trying to make a JTable
that has column spans available. Specifically, I am looking to nest a JTable
inside another JTable
, and when the user clicks to view the nested table, it should expand to push down the rows below and fill the empty space. This is similar to what you see in MS Access where you can nest tables, and clicking the expand button on a row will show you the corresponding entries in the nested table.
If someone knows of a way to perform a column span with JTable
, can you please point me in the right direction? Or if you know of an alternative way to do this, I am open to suggestions. The application is being built with Swing. Elements in the table, both high level and low level, have to be editable in any solution. Using nested JTable
s this won't be a problem, and any other solution would have to take this into consideration as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要为主表编写自己的TableUI。 使用您自己的 TableModel 来保存附加数据(例如扩展行)也很有帮助。 但这是可选的。
我编写了一个 equals TableUI 来展开一行并显示文本编辑器。 在 TableUI 中,您需要使用 table.setRowHeight(height) 动态更改行高。 此外,还需要从 BaseTableUI 复制一些内容,因为您无法访问私有内容。
You need to write your own TableUI for the master table. It can also helpful to use your own TableModel to save additional data like if a row is expanded. But this is optional.
I write an equals TableUI that expand a row and show an text editor. In the TableUI you need to change the the row hight dynamically with table.setRowHeight(height). Also it is necessary to copy some stuff from the BaseTableUI because you can not access the private stuff.
基于 Code-Guru 的代码:
来源:http://www.codeguru.com/java /articles/125.shtml(自 2012 年以来不可用,现在参见 web archive)
其他资源:
Based on Code from Code-Guru:
Source: http://www.codeguru.com/java/articles/125.shtml (unavailable since 2012, see now in web archive)
Other ressources:
作为正确方向的指针,请尝试 SwingWiki 上的这篇文章,其中解释了列的 TableUI 方法跨越得很好。 在此之前,我还尝试了一些替代方法,例如覆盖 TableCellRenderer 绘制方法,但没有取得太大成功。
As a pointer in the right direction, try this article at SwingWiki that explains the TableUI method of column spanning quite well. Before this, I also tried some alternatives such as overriding the TableCellRenderer paint methods without much success.