【发布时间】:2020-01-17 08:26:51
【问题描述】:
好的,所以我有一个 IndirectListModel<MyRow> 允许多选我绑定到 JTable 的行,我为其设置了以下渲染器的所有单元格:
private static class MyVerificationHighlightingCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int columnIndex) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, rowIndex, columnIndex);
MyRow row = ...
if (row.isValid()) {
setBackground(Background.OK);
} else {
setBackground(Background.ERROR);
}
return this;
}
}
This works ... ONLY when the rows are selected.
即我选择行,它们变为绿色或红色,具体取决于它们的isValid() 方法。但是,一旦我选择了其他内容,新的选择就会获得背景颜色,而其他选择会恢复为白色/条纹。
为什么?更重要的是,如何让我的表格在未选择行时使用我想要的颜色?
【问题讨论】:
-
如果您能给我们一个minimal reproducible example,那就太好了。
-
@GeorgeZ。很想……除非我不被允许。
-
(1-) 除了我不允许 - 你当然可以。 minimal reproducible example 的重点是演示问题。您无需发布真实数据。我们只是要求一个带有 JList 和自定义渲染的框架。没有什么专有的。
-
这是 JGoodies 特有的行为,而不是纯 Swing。
标签: java swing jtable tablecellrenderer