我有一个 JTable,这样:
ID #: Name:
0 Entry 0
1 Entry 1
2 Entry 2
当变量:
private int HighlightEntryID = 2;
设置为 ID #,然后 JTable 应该能够突出显示相应的条目。
我创建了一个自定义单元格渲染器并使用以下代码:
TableColumn column = CISTable.getColumnModel().getColumn(0);
column.setCellRenderer(new CustomCellRenderer());
我根据 ID # 列呈现单元格。我的问题是:
- 它仅突出显示特定的(行、列)条目。我想突出显示整行。如何突出显示同一行中的其他列?
- 当变量:HighlightEntryID 更改时,JTable 不会自动反射(reflect)更改。我必须手动刷新表格。如何自动刷新?
最佳答案
It only highlights a specific (row, column) entry. I want to highlight the whole row. How do I highlight other columns in the same row?
我喜欢使用Table Row Rendering为此。
When the variable: HighlightEntryID is changed, the JTable doesn't automatically reflect the change. I must refresh the table manually. How do I refresh it automatically?
调用以下命令强制重新绘制整个表格:
table.repaint();
关于Java JTable——当外部变量更改时突出显示某个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4541043/