I don\'t understand how alternate row coloring works in Nimbus. It seems just crazy!!! I would like to clear things up here.
For the demonstration, let\'s say that <
Looks like the interference of several bugs ...
For changing both default table background and default striping, the expected (not only yours, mine as well) configuration of the UIManager (same for all LAFs which respect the alternateRow property) would be:
UIManager.put("Table.background", Color.RED);
UIManager.put("Table.alternateRowColor", Color.PINK);
Doesn't work, neither for Metal nor for Nimbus
Underlying reason for the first can be found in DefaultTableCellRenderer:
Color background = unselectedBackground != null
? unselectedBackground
: table.getBackground();
if (background == null || background instanceof javax.swing.plaf.UIResource) {
Color alternateColor = DefaultLookup.getColor(this, ui, "Table.alternateRowColor");
if (alternateColor != null && row % 2 != 0) {
background = alternateColor;
}
}
It's logic is crooked: the alternate color is only taken if the table's background is a colorUIResource, a rather weak distinction. Anyway, it leads us to next try:
UIManager.put("Table.background", new ColorUIResource(Color.RED));
UIManager.put("Table.alternateRowColor", Color.PINK);
This looks fine (except the typical issue with a checkbox renderer, but that's yet another bug story ;-) for metal, still no luck for Nimbus.
Next step is look up Nimbus defaults which might be related, and apply (after! setting the LAF):
UIManager.getLookAndFeelDefaults().put("Table:\"Table.cellRenderer\".background",
new ColorUIResource(Color.RED));
Edit (as it was asked in the comments)
JXTable tries to side-step the problem entirely - its means for striping is a Highlighter retrieved from the HighlighterFactory. Needs to go dirty with Nimbus by removing the alternateRowColor property from the lookAndFeelDefaults and add it with a new key "UIColorHighlighter.stripingBackground"