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.
2 Answers
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

- 51,061
- 28
- 99
- 211
-
Thanks. Both answers were very helpful and useful. I accepted this one only because using this example was easier for me to understand that I will ever have more control over a calendar widget if I build my own :) Seriously the JXMonthView is a nice piece of code, very easy to use, though no really meant for situations when you desire to modify it. Thanks again for your time. – Boro Apr 01 '11 at 07:25
I think you can just get the MonthViewUI and make the changes you need. Take a look at the JXMonthView
source.
-
OK. I am looking into it at the moment, but can you think of a simple example that would help me get it faster how to do it? – Boro Mar 29 '11 at 08:24
-
@Boro, not sure. Would have to see example code. Sounds like that should be another question. – jzd Mar 29 '11 at 11:21
-
Honestly I read the doc, and I wrote my own UI. I installed it, I created header handler etc. No success. I always end up with the default look, why?! For example I would at least to be able to install the SpinningCalendarHeaderHandler, can you help me with this, please fa silly example would be a blast. I love the lib but I do not get why they do not expose child components so you can get them with getComponents(): http://www.jarvana.com/jarvana/view/org/swinglabs/swingx/1.6.1/swingx-1.6.1-sources.jar!/org/jdesktop/swingx/plaf/basic/SpinningCalendarHeaderHandler.java?format=ok – Boro Mar 29 '11 at 11:27
-
Can you, for example, show me how to change the header from basic to the spinner one, link in my previous comment? Thanks. – Boro Mar 29 '11 at 11:28