Swing:带有标题行的表格

发布于 2024-08-20 20:44:14 字数 352 浏览 4 评论 0 原文

我有一个显示对象列表的表格;为了清楚起见,我们将他们称为Employee

该表显示 Employee 对象,这些对象是给定父对象的子对象,该父对象也是 Employee。我想要做的是显示一个带有父对象的特殊标题行,位于正常列标题的上方(如果可能)或下方,但以不同的颜色。我希望父对象行的列的大小与表的其余部分同步调整,并且我不希望父对象可供选择。

(基本上我想显示一个独立的子对象表,以及具有相同字段的单独的父“上下文”。)

有没有好的方法可以做到这一点? (一个表有一个特殊行?两个表,其中父上下文对象的表只有 1 行垂直,并且水平调整大小以匹配另一个表?)

I have a table showing a list of objects; let's call them Employee for clarity's sake.

The table shows Employee objects that are child objects of a given parent object which is also an Employee. What I would like to do is show a special header row with the parent object, either above (if possible) or below the normal column heading, but in a different color. I want the columns of the parent object row to be resized in sync with the rest of the table, and I don't want the parent object to be selectible.

(Basically I want to show a self-contained table of child objects, along with a separate parent "context" which has the same fields.)

Is there a good way to do this? (one table with a special row? two tables, where the one for the parent context object is only 1 row vertical, and horizonally resizes to match the other?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2024-08-27 20:44:14

我认为您应该使特殊行始终呈现在表中的第 0 行,使用您需要更改颜色等的任何渲染器。这样您就可以免费调整大小。

为了使该行不可选择,我认为您需要覆盖 createDefautSelectionModel 方法到您自己的 ListSelectionModel。您可以覆盖 DefaultListSelectionModel忽略 setAnchorSelectionIndex 方法和 setLeadSelectionIndex 方法。

应该可以,但还没有测试过。

I think you should make the special row always be rendered at row 0 in the table, using whatever renderer you need to change the color etc. That way you get the resizing for free.

In order to make this row unselectable, I think you'll need to override the createDefautSelectionModel method to your own implementation of ListSelectionModel. You can probably override the DefaultListSelectionModel to ignore a value of 0 (first row) in the setAnchorSelectionIndex method and setLeadSelectionIndex methods.

Should work, but haven't tested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文