// Overridden for performance reasons. ----> @Override public boolean isOpaque() { Color back = getBackground(); Component p = getParent(); if (Objects.nonNull(p)) { p = p.getParent(); } // p should now be the JTable. boolean colorMatch = Objects.nonNull(back) && Objects.nonNull(p) && back.equals(p.getBackground()) && p.isOpaque(); return !colorMatch && super.isOpaque(); }
public Component getTableCellRendererComponent( JTable table, Setting owner, Object value, boolean isSelected, boolean hasFocus, boolean isEnabled, int row, int column) { // renderer.setMargin(new Insets(0, 2, 4, 2)); if (isSelected) { renderer.setForeground(table.getSelectionForeground()); panel.setBackground(table.getSelectionBackground()); blank1.setBackground(table.getSelectionBackground()); blank2.setBackground(table.getSelectionBackground()); } else { renderer.setForeground(table.getForeground()); panel.setBackground(table.getBackground()); blank1.setBackground(table.getBackground()); blank2.setBackground(table.getBackground()); } if (hasFocus) { panel.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); } else { panel.setBorder(new EmptyBorder(1, 2, 2, 1)); } if (value instanceof Color) { Color col = (Color) value; // System.out.println("setting background to "+col.toString()); renderer.setText("[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]"); renderer.setEnabled(isEnabled); renderer.setFont(font); colourPanel.setBackground(col); } else if (value instanceof ArrayList) { ArrayList values = (ArrayList) value; if (values.size() > 0) { // if we have multiple properties selected. Color last = null; boolean allSame = true; for (int i = 0; i < values.size(); i++) { if (values.get(i) instanceof Color) { Color str = (Color) values.get(i); if (last != null) { if (!str.equals(last)) { allSame = false; break; } last = str; } else { last = str; } } } if (allSame) { renderer.setText( "[" + last.getRed() + "," + last.getGreen() + "," + last.getBlue() + "]"); renderer.setEnabled(isEnabled); renderer.setFont(font); colourPanel.setBackground(last); } else { renderer.setText("(Different values)"); renderer.setEnabled(isEnabled); renderer.setFont(font); colourPanel.setBackground(Color.lightGray); panel.setBackground(Color.lightGray); blank1.setBackground(Color.lightGray); blank2.setBackground(Color.lightGray); } } } return panel; }