JTable 禁用单元格中的复选框
您好,我有一个 JTable,我想将所有禁用的复选框单元格灰显,我尝试使用自定义渲染器检查 isEnabled(),然后更改背景颜色,但仍然无法正常工作。 有什么建议吗? 谢谢!!!
Hello I have a JTable And i want to grey out all the disabled checkbox cells i tried with a custom renderer checking isEnabled() and then changing the background color but still not workin.
Any suggestions?
thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如概念:编辑器和渲染器,“单个单元格渲染器通常用于绘制包含相同类型数据的所有单元格。”您需要在 表模型。
附录:作为一个具体示例,此示例中的数据模型是一个简单的
Date
实例数组。如下所示重写getTableCellRendererComponent()
会导致禁用奇数天。在这种情况下,奇数是Date
值本身固有的属性,但可以查询模型以获取任何相关属性。附录:在上面的示例中,
DateRenderer
被调用,因为TableModel
返回类型标记日期.class
,它已被设为默认值。可以通过重写
prepareRenderer()
来获得相同的外观,如下所示,但该方法会针对所有单元格调用,而与类无关。因此,prepareRenderer()
非常适合影响整行,如 表格行渲染。As noted in Concepts: Editors and Renderers, "a single cell renderer is generally used to draw all of the cells that contain the same type of data." You'll need to maintain the
enabled
state in your table model.Addendum: As a concrete example, the data model in this example is a simple array of
Date
instances. OverridinggetTableCellRendererComponent()
as shown below causes odd days to be disabled. In this case, being odd is a property inherent to theDate
value itself, but the model could be queried for any related property at all.Addendum: In the example above, the
DateRenderer
is evoked because theTableModel
returns the type tokenDate.class
, for which it has been made the default.An identical appearance can be obtained by overriding
prepareRenderer()
as shown below, but the method is invoked for all cells, irrespective of class. As a result,prepareRenderer()
is ideal for affecting entire rows, as shown in Table Row Rendering.