boolean rowSelAllowed = table.getRowSelectionAllowed(); boolean colSelAllowed = table.getColumnSelectionAllowed(); boolean isSel = false; if (rowSelAllowed && colSelAllowed || !rowSelAllowed && !colSelAllowed) isSel = table.isCellSelected(row, col); else isSel = table.isRowSelected(row) && table.getRowSelectionAllowed() || table.isColumnSelected(col) && table.getColumnSelectionAllowed();    ListSelectionModel rowSel = table.getSelectionModel(); ListSelectionModel colSel = table.getColumnModel().getSelectionModel(); boolean hasFocus = table.hasFocus() && table.isEnabled() && rowSel.getLeadSelectionIndex() == row && colSel.getLeadSelectionIndex() == col;  Component comp = rend.getTableCellRendererComponent(table, data.getValueAt(row, col), isSel, hasFocus, row, col);
Component comp = table.prepareRenderer(rend, row, col);
  void paintCell(Graphics g, int row, int col, Rectangle bounds,                 TableCellRenderer rend, TableModel data,                 int rowLead, int colLead)  {    boolean rowSelAllowed = table.getRowSelectionAllowed();    boolean colSelAllowed = table.getColumnSelectionAllowed();    boolean isSel = false;    if (rowSelAllowed && colSelAllowed || !rowSelAllowed && !colSelAllowed)      isSel = table.isCellSelected(row, col);    else      isSel = table.isRowSelected(row) && table.getRowSelectionAllowed()           || table.isColumnSelected(col) && table.getColumnSelectionAllowed();    // Determine the focused cell. The focused cell is the cell at the    // leadSelectionIndices of the row and column selection model.    ListSelectionModel rowSel = table.getSelectionModel();    ListSelectionModel colSel = table.getColumnModel().getSelectionModel();    boolean hasFocus = table.hasFocus() && table.isEnabled()                       && rowSel.getLeadSelectionIndex() == row                       && colSel.getLeadSelectionIndex() == col;    Component comp = rend.getTableCellRendererComponent(table,                                                       data.getValueAt(row, col),                                                       isSel, hasFocus, row, col);        rendererPane.paintComponent(g, comp, table, bounds);        // FIXME: this is manual painting of the Caret, why doesn't the     // JTextField take care of this itself?    if (comp instanceof JTextField)      {        Rectangle oldClip = g.getClipBounds();        g.translate(bounds.x, bounds.y);        g.clipRect(0, 0, bounds.width, bounds.height);        ((JTextField)comp).getCaret().paint(g);        g.translate(-bounds.x, -bounds.y);        g.setClip(oldClip);      }  }