开发者

JXTable with DefaultTableCellrenderer and alternate striping highlighter

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 开发者_StackOverflow中文版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?


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)


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜