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

前端 未结 3 1879
深忆病人
深忆病人 2020-11-22 00:12

Given a JTable with a column of type Boolean.class, the default renderer is a JCheckBox. It\'s easy enough to select individual cells based on a us

3条回答
  •  清酒与你
    2020-11-22 00:22

    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 (e.g. 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, (e.g. 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 to be controlled by ourselves
    • examples are around (e.g. 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 appearance

提交回复
热议问题