开发者

Swing: table with header row

开发者 https://www.devze.com 2022-12-19 18:47 出处:网络
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. Wh

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 开发者_StackOverflow社区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?)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消