-1

Alright, so I have an IndirectListModel<MyRow> allowing for multi-selection of rows that I bind to a JTable, all cells of which I set the following renderer for:

private static class MyVerificationHighlightingCellRenderer extends DefaultTableCellRenderer {
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int columnIndex) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, rowIndex, columnIndex);

        MyRow row = ...

        if (row.isValid()) {
            setBackground(Background.OK);

        } else {
            setBackground(Background.ERROR);
        }

        return this;
    }
}

This works ... ONLY when the rows are selected.

I.e. I select rows, they turns either green or red, depending on their isValid() methods. However, as soon as I select something else, the new selection gets the background colours and the others go back to white/ striped.

Why? And more importantly, how can I make my table use the darn colours I want it to have when the rows are NOT selected?

User1291
  • 7,664
  • 8
  • 51
  • 108
  • It would be great if you could give us a [mcve]. – George Z. Sep 16 '19 at 13:41
  • @GeorgeZ. would love to ... except I'm not allowed to. – User1291 Sep 16 '19 at 13:44
  • (1-) *except I'm not allowed to* - of course you are. The point of the [mre] is to demonstrate the problem. There is no need for you to post real data. We are just asking for a frame with a JList and a custom render. There is nothing proprietary about that. – camickr Sep 16 '19 at 20:59
  • This is JGoodies-specific behavior, not pure Swing. – cheppsn Jan 28 '20 at 23:00

1 Answers1

1

Ok, so what happens is that we're using the JGStripedTable class in the background. This thing generates the stripes that normally get displayed.

We need to tell it NOT to do that by adding

putClientProperty("JGoodies.customBackground", true);

into our getTableCellRendererComponent method before we return.

User1291
  • 7,664
  • 8
  • 51
  • 108