I am trying to implement a button such that when it is clicked, the color of a cell in that row changes colors. I have a cellRenderer class:
public class MyCellRenderer extends javax.swing.table.DefaultTableCellRenderer {
public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column) {
java.awt.Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
cellComponent.setBackground(java.awt.Color.RED);
return cellComponent;
}
}
that gets invoked as follows:(for column 15 let's say):
MyCellRenderer mcr = new MyCellRenderer();
Mytable.getColumnModel().getColumn(15).setCellRenderer(mcr);
notice how it gets invoked on a ColumnModel object. Is there a method to select a cell (row, column) and change its color based on the coordinates. Such that it can be invoked by a JTable object? For example:
Mytable.colorCell(1,7); //colors cell in row 1, column 7
Thank you