SwingX how to get child components of JXMonthView?
Question
Anyone had experience with using SwingX? I want to use JXMonthView and modify its components. I can use it without a sweat. But when I try to actually get my hands on the underlying child components I fail. I would like to change the font style and color used only by the component which displays the month. I am using SwingX 1.6.2.
Solution
Basically, a JXMonthView has no components to modify (for the one exception, see below). Instead, it's painting is done by a rendering mechanism, similar to rendering of cells a table/tree/list. The SwingX'ish way to customize the visual properties of the rendering is to decorate the rendering component by a Highlighter.
Unfortunately, the evolution got stuck somewhere in the middle: there's no easy and no really public support to do so. The collaborators are in plaf.basic:
- CalendarRenderingHandler: the interface to implement
- BasicCalendarRenderingHandler: a package-private default implementation
- BasicMonthViewUI: has a factory method to create and return the handler to use
So customizing the visuals of a JXMonthView is quite a chore, involving a lot of subclassing. On the brighter side: swinglabs-demos has an example of how that can be done
CU Jeanette
PS: you might consider to post SwingX specific questions at the SwingLabs Forum - though it's not as active as it used to be, due to migration woes of java.net, sigh
OTHER TIPS
I think you can just get the MonthViewUI and make the changes you need. Take a look at the JXMonthView
source.