import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.JLabel; import java.awt.Component; import java.awt.Color; import javax.swing.table.TableCellRenderer; class Program extends JFrame { private JTable tabla; public Program() { setLayout(null); tabla = new JTable(9, 9); tabla.setBounds(20, 20, 300, 200); int columnWidht = 20; int rowHeight = 25; for(int i=0; i<9; i++) tabla.getColumnModel().getColumn(i).setPreferredWidth(columnWidht); for(int i=0; i<9; i++) tabla.setRowHeight(i, rowHeight); tabla.setDefaultRenderer(Object.class, new MyTableCellRenderer()); tabla.getModel().setValueAt(Color.red, 3, 3); tabla.getModel().setValueAt(Color.red, 3, 5); add(tabla); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setVisible(true); } public static void main(String args[]) { new Program(); } class MyTableCellRenderer extends JLabel implements TableCellRenderer { MyTableCellRenderer() { setOpaque(true); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { setBackground((Color) value); return this; } } }