[SWINGX-1390] JXTable doesn't respect TableCellRenderer background colors Created: 01/Feb/11  Updated: 01/Feb/11  Resolved: 01/Feb/11

Status: Resolved
Project: swingx
Component/s: Table
Affects Version/s: 1.6.2
Fix Version/s: 1.6.3

Type: Bug Priority: Major
Reporter: jason_s Assignee: Karl Schaefer
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

See http://stackoverflow.com/questions/4856804/swing-table-cell-rendering-doesnt-work-right-for-jxtable

The background color in my TableCellRenderer seems to get overridden for rows unless they are selected.



 Comments   
Comment by jason_s [ 01/Feb/11 ]

(platform on which I run = Windows XP, and I'm running JRE 1.6.0_20)

Comment by Karl Schaefer [ 01/Feb/11 ]

First, SwingX suggests not using TableCellRenderers that are a subclass of DefaultTableCellRenderer. It is a poor implementation of a renderer and it also does not take advantage of the SwingX rendering paradigm of StringValues (for display text) and Highlighters for visual decoration. I'd recommend replacing your custom DTCR subclass with a DefaultTableRenderer that Highlighters, such as HighlighterFactory.createAlternateStriping().

Second, if you continue using the DTCR subclass and it handles colors correctly (because DTCR does not), you may need to call JXTable.putClientProperty(JXTable.USE_DTCR_COLORMEMORY_HACK, null). This should causes JXTable to honor your colors.

Comment by Karl Schaefer [ 01/Feb/11 ]

Resolving as won't fix.

Comment by jason_s [ 01/Feb/11 ]

OK, thanks.

It is a poor implementation of a renderer and it also does not take advantage of the SwingX rendering paradigm of StringValues (for display text) and Highlighters for visual decoration.

Are there any online resources to provide guidance for Highlighter implementations that are row or cell-value dependent? (rather than position-dependent) I've never used a Highlighter before.

Also, I don't want to highlight the entire row, just certain columns.

Comment by Karl Schaefer [ 01/Feb/11 ]

Highlighter may be added to specific columns by adding the Highlighter to the TableColumnExt in the TableColumnModel or my using a HighlightPredicat.ColumnHighlightPredicate. You can create custom HighlightPredicates for any purpose that you define. HighlightPredicate offers may examples of how to create a HighlightPredicate. When the predicate returns true, your Highlighter will affect the visual output of the renderer; false disables the highlighter. You can find more resources in the class and package documentation, the wiki (link on SwingX page) or in our forums (http://www.java.net/forums/javadesktop/java-desktop-technologies/swinglabs).

Please follow up there with any questions to make it easier for the next guy trying to find the same answers.

Generated at Sun Sep 25 05:37:45 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.