可能重复(字体,颜色...?):
Swing - Setting the color of a cell based on the value of a cellJava的JTable中:我怎样才能改变一个特定细胞的属性
我有一个电子表格类,包含一个JTable及其TableModel。 而我的主窗口包含这个电子表格和一个按钮列表,例如一个大胆的。
我能顺利拿到选定单元格(见下面的代码),但我不知道该怎样来改变它的内容和字体,颜色等
public void actionPerformed(ActionEvent e)
{
int rowToUpdate = -1, columnToUpdate = -1;
for(int i = 0 ; i < tableToUpdate.getRowCount() ; i++)
for (int j = 0 ; j < tableToUpdate.getColumnCount() ; j++)
if(tableToUpdate.isCellSelected(i, j)){ rowToUpdate = i; columnToUpdate = j; }
if(rowToUpdate >= 0 && columnToUpdate >= 0)
{
if(e.getSource == boldButton)
{
// Here, how to change the bold of the cell(rowToUpdate,columnToUpdate)
}
}
}