【发布时间】:2014-02-10 21:01:54
【问题描述】:
我正在尝试更改 JTable 中一列中一个或多个特定单元格的颜色。我在这里看到的答案都是指这种特殊的方法;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component y = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
y.setBackground(new Color(255,0,0));
return y;
}
但问题是我不明白这是如何工作的,在我的其他课程中,我有一个字符串 Jtable,我想根据它们的字符串值更改某些单元格的颜色,但是我只找到了解决方案请允许我更改 jtable 中整列单元格的颜色,而不是特定单元格的颜色。
【问题讨论】:
-
您的问题似乎有点为时过早。您需要学习如何使用 TableCellRenderer,例如扩展 DefaultTableCellRenderer 或 AbstractTableCellRenderer。如果您阅读 JTable tutorial 和相应的 API,并更加努力地搜索此站点,您会发现至少需要初步了解此站点的所有信息。
标签: java swing colors jtable cell