我有一个显示对象列表的表格;为了清楚起见,我们将他们称为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?)
发布评论
评论(1)
我认为您应该使特殊行始终呈现在表中的第 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.