The table is filled with 0 and 1. It is necessary to paint over the cell in the JTable with a different color if it is written in the cell 1. I have so far managed to paint over the entire row. Code below.
JTable class:
public class JTableExample { JTable jTable; TabModel tModel; ArrayList tableDatas; Renderer renderer = new Renderer(); JTableExample() { JFrame frame = new JFrame("Printer Imitation"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(300, 500); frame.setLocationRelativeTo(null); frame.setLayout(new FlowLayout()); JLabel label = new JLabel("Введите строки матрицы"); JTextField textField = new JTextField(20); JButton buttonAdd = new JButton("Ввод"); JButton buttonDel = new JButton("Очистить"); buttonAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { String values = textField.getText().replaceAll("\\s", ""); String[] strValues = values.split(","); tableDatas.add(new TableData(strValues[0], strValues[1], strValues[2], strValues[3], strValues[4], strValues[5], strValues[6], strValues[7], strValues[8], strValues[9], strValues[10])); tModel.fireTableDataChanged(); } }); buttonDel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tModel.clearHistory(); textField.setText(""); } }); tableDatas = new ArrayList(); tModel = new TabModel(tableDatas); jTable = new JTable(tModel); for (int i = 0; i < jTable.getColumnCount(); i++) { jTable.getColumnModel().getColumn(i).setCellRenderer(renderer); jTable.setPreferredSize(new Dimension(200, 145)); frame.add(jTable); frame.add(label); frame.add(textField); frame.add(buttonAdd); frame.add(buttonDel); frame.setVisible(true); } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new JTableExample(); } }); }} Renderer class:
public class Renderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String cellvalue = table.getValueAt(row, table.getColumnModel().getColumnIndex("1")).toString(); if(cellvalue.equals("1")){cell.setBackground(Color.RED);} return cell; }}