swingx
  1. swingx
  2. SWINGX-1390

JXTable doesn't respect TableCellRenderer background colors

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.6.2
    • Fix Version/s: 1.6.3
    • Component/s: Table
    • Labels:
      None

      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.

        Activity

        Hide
        jason_s added a comment -

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

        Show
        jason_s added a comment - (platform on which I run = Windows XP, and I'm running JRE 1.6.0_20)
        Hide
        Karl Schaefer added a comment -

        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.

        Show
        Karl Schaefer added a comment - 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.
        Hide
        Karl Schaefer added a comment -

        Resolving as won't fix.

        Show
        Karl Schaefer added a comment - Resolving as won't fix.
        Hide
        jason_s added a comment -

        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.

        Show
        jason_s added a comment - 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.
        Hide
        Karl Schaefer added a comment -

        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.

        Show
        Karl Schaefer added a comment - 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.

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            jason_s
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: