4

I updated to SwingX-1.6.2 but found problems that didn't appear in 1.6. The colors of the JXTable cells looks odd. I use a highlighter with an alternate striping (HighlighterFactory.createAlternateStriping) for the colors and a subclass of DefaultTableCellRenderer for settings text, font,...

Since 1.6.1 it seems that the colors of the highlighter are ignored if a custom cell renderer is set. The documentation says there is a hack, but it does not work.

Has anybody a solution for this?

Stephan
  • 4,395
  • 3
  • 26
  • 49
  • 1
    +1 this sounds interesting could you please link us to the resources you are referring to? or even give us [SSCCE](http://sscce.org) to work with? – Boro May 27 '11 at 10:10

3 Answers3

4

For custom cell rendering in SwingX,

  • never-ever subclass xxRenderer
  • never-ever subclass JXTable (nor JXList, JXTree/Table)

Instead

  • implement/use StringValue to configure the "content" aspects, like text, icon ..
  • use/implement Highlighter to configure the "visual" aspects, like color, font, painter
  • if conditional visual decoration are required, implement/use HighlightPredicate and configure the Highlighter with it
  • configure a xxRenderer with the StringValue and/or Highlighter

Edit:

if unsupported rendering component types are needed, the way to go is to implement a ComponentProvider. That's a bit of work, because the provider has to fulfill a strict contract (like resetting the guaranteed property values, respect the StringValue, ... see the api doc) but it's needed once per component type only. Once done, the same provider can be used in all types of collection components (list JXList, JXComboBox, JXTree/Table)

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • Ok, but what how can I use custom renderers like checkboxes, radiobuttons or comboboxes without extending the renderer? – Stephan Jun 14 '11 at 10:22
0

I don't know how JXTable does its highlighting but you can always do this yourself. See Table Row Renderering.

camickr
  • 321,443
  • 19
  • 166
  • 288
0

I wasn't able to reproduce the issue in a SSCCE, but I in my (very complex) application I solved it by using a renderer inherited from SwingX's DefaultTableRenderer instead of java's DefaultTableCellRenderer.

Stephan
  • 4,395
  • 3
  • 26
  • 49
  • 1
    nono never-ever subclass xxRenderer in SwingX (we probably should have made them final too emphasize ;-), they are nothing but legacy glue – kleopatra Jun 13 '11 at 10:37
  • If the function of JXTable is completely different to JTable, you probably should have created a new class for it, instead extending JTable. Inheritance should only extend behavior, and never limit it. – Stephan Jun 20 '11 at 08:05
  • he? It's a perfectly valid extension as it enhances core functionality considerably. If you don't want to learn how to use the enhancements, feel free to stick to a plain JTable. And note: subclasses of _core_ default table renderer don't play nice because that _core_ implementation is _BROKEN_ – kleopatra Jun 20 '11 at 13:56
  • 1
    Stephan's point is that it then violates the Liskov Substitution Principle. (But so do the Java Collection classes.) – Jason S Mar 20 '12 at 17:38