0

This code allows the user to click on a cell in a JTable which changes colour. Is there a way to change the colour of that cell permanently when it has been clicked on once? Here is my code for table and cell renderer.

JPanel outerPanel;
private PathGame pg;

private Component pathGame() {

    JTable gameTable;
    gameTable = new JTable(row, column);       
    gameTable.setDefaultRenderer(Object.class, myRenderer);
    outerPanel.add(new JScrollPane(gameTable), BorderLayout.CENTER);

    return outerPanel;
}

public class MyRenderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        if (hasFocus) {                
            if (pg.showCell(row, column).equals(Cell.R)) {
                setBackground(Color.red);                    

            } else if (pg.showCell(row, column).equals(Cell.B)) {
                setBackground(Color.blue);

            } else if (pg.showCell(row, column).equals(Cell.E)) {
                setBackground(table.getBackground());
            }
        } else {
            setBackground(table.getBackground());
        }

        return this;
    }

}
Lubblobba
  • 1
  • 1

0 Answers0