How can I put a control in the JTableHeader of a JTable?

1 Like

There are two parts of the problem as I see it :-

Usability: inventing ui-interaction/elements is prone to confusing users. In no particular order

 

the column header title is meant to describe the content of the column, that content description is lost when in replacing it with an action description

it's not immediately (for me, the dumbest user on earth :-) clear that the header cell has the function of a toggle button. Accidentally clicking it will loose all earlier content state in that column

So even if interaction analysis comes out with a clear we-do-need/want-it,

 

action only in-addition to the content

use a widget that's clearer, f.i. a tri-state checkbox (all-de-/selected, mixed content). Also, de-/selecting must both be possible from mixed content. On second thought, a checkbox probably isn't the best choice either, didn't dig further

minimize the possibility to accidentally (just for me :-) change bulk state, f.i. by a clear visual separation of an active area (the checkbox icon) from the "normal header" region.

Technical aspects

TableHeader is not designed for "live" components, whatever is wanted has do be controlled by ourselves

examples are around, f.i. JIDE grid supports adding components

fiddling with header tends to look unattractive because it's not trivial to change the renderer and at the same time keep the LAF provided appearence