如何将控件放在JTable的JTableHeader中? [英] How can I put a control in the JTableHeader of a JTable?

查看:144
本文介绍了如何将控件放在JTable的JTableHeader中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于 JTable ,类型为 Boolean.class 默认渲染器 JCheckBox 。根据 用户选择,可以轻松选择单个单元格 ,但也可以方便地选中所有复选框或不选中复选框。这些最近 示例在表头中使用 JCheckBox 提到,但是实施很尴尬,没有吸引力。如果我不需要对列进行排序,我怎样才能在 JTableHeader

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 user selection, but it may be convenient to select all or none of the check boxes, too. These recent examples mentioned using JCheckBox in the table header, but the implementation was awkward and unappealing. If I don't need to sort the column, how can I put a well-behaved control in the JTableHeader?

附录:为方便起见,我已将 sscce 添加为回答,但我很乐意接受一个解决的答案问题的表现良好

Addendum: For convenience, I've added my sscce as an answer, but I'd be pleased to accept an answer that addresses the well-behaved aspect of the problem.

推荐答案

问题分为两部分(我认为: - )

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

可用性:发明UI交互/元素容易使用户感到困惑。没有特别的顺序:

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

所以即使交互式分析出现明确的我们需要/ want-it,

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


  • 仅对内容采取行动

  • 使用小部件更清晰(例如,三态复选框全部/选择,混合内容)。此外,必须从混合内容中进行去/选择。第二个想法,一个复选框可能也不是最好的选择,没有进一步挖掘

  • 最小化意外的可能性(仅适用于我:-)改变批量状态,(例如通过从普通标题区域清晰可视区分活动区域 - 复选框图标。

技术方面


  • TableHeader不适用于实时组件。无论需要什么都必须由我们自己控制

  • 示例(例如JIDE网格支持添加组件)

  • 摆弄标题往往看起来没有吸引力因为改变渲染器并同时保持LAF提供的外观并非易事

这篇关于如何将控件放在JTable的JTableHeader中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆