//新手问题
我有一个带有几乎基本单元格渲染器的 JTable(它以不同的方式为线条着色)。 我注意到我的单元格渲染器一直在为屏幕上显示的行运行,即使我没有对表格做任何事情。
事情就该这样吗?它不应该对每个单元格进行一次渲染,仅此而已吗? 我怎样才能让它停止,并且只在变化时重新计算?
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
log.debug("Building cell : " + row + "," + column);
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
Filter filter = (Filter)table.getModel().getValueAt(row, Column.CLASSIFICATION.getIndex());
comp.setBackground(filter.getColor());
return comp;
}
最佳答案
在@Steve McLeod 的提议下,我开始构建一个具有相同错误的示例代码,直到那时我才意识到在我的一个 CellRenderer 中
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
log.debug("Building a list for " + row + "," + column);
setListData(((Vector<String>)value).toArray());
setToolTipText("This is a tool tip for " + row + "," + column);
table.setRowHeight(row, Math.max(1, getPreferredSize().height));
Filter filter = (Filter)table.getModel().getValueAt(row, Column.CLASSIFICATION_RESULT.getIndex());
setBackground(filter.getColor());
return this;
}
我有一行:
table.setRowHeight(row, Math.max(1, getPreferredSize().height));
它不断地改变行 line ,而同一行中的其他渲染器做同样的事情...... 所以他们不断地互相射击。
关于java - 为什么我的 JTable CellRenderer 一直在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4538873/