@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { textLabel.setFont(table.getFont()); textLabel.setText(Objects.toString(value, "")); textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder); FontMetrics fm = table.getFontMetrics(table.getFont()); Insets i = textLabel.getInsets(); int swidth = iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right; int cwidth = table.getColumnModel().getColumn(column).getWidth(); dim.width = swidth > cwidth ? cwidth : swidth; if (isSelected) { textLabel.setOpaque(true); textLabel.setForeground(table.getSelectionForeground()); textLabel.setBackground(table.getSelectionBackground()); iconLabel.setIcon(sicon); } else { textLabel.setOpaque(false); textLabel.setForeground(table.getForeground()); textLabel.setBackground(table.getBackground()); iconLabel.setIcon(nicon); } return panel; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { getModel().setRollover(highlighter.isHighlightableCell(row, column)); if (isSelected) { setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(table.getBackground()); // setBackground(row % 2 == 0 ? table.getBackground() : Color.WHITE); //Nimbus } setSelected(Objects.equals(value, Boolean.TRUE)); return this; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String str = Objects.toString(value, ""); if (highlighter.isHighlightableCell(row, column)) { setText("<html><u>" + str); setForeground(isSelected ? table.getSelectionForeground() : HIGHLIGHT); setBackground(isSelected ? table.getSelectionBackground().darker() : table.getBackground()); } else { setText(str); setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); setBackground(isSelected ? table.getSelectionBackground() : table.getBackground()); } return this; }