This section contains issues that prevent the JDatePicker suite components to work properly and are beyond our control.
When an applet is reloaded, static blocks of the loaded classes are not reexecuted. The JDatePicker suite components use such blocks to initialize the UI delegates and this results in a "UIDefaults.getUI() failed: no ComponentUI class for: " exception.
To fix this problem, you should make the initializations that are lost in the static blocks, explicitly. In the init() method of your applet, before calling the code that creates the JDatePicker suite components add the following code:
UIManager.put("MonthUI", DefaultMonthUI.class.getName());
UIManager.put("MonthViewUI", DefaultMonthViewUI.class.getName());
UIManager.put("DatePickerUI", BasicDatePickerUI.class.getName());
UIManager.put("DateFieldUI", BasicDateFieldUI.class.getName()); Here is how this is done in our demo applet. This is just an example with the UI delegates used by default. For more information about UI delegates, please read this section.
An important responsibility of a Swing look and feel is to provide a defaults table. Among other things, this table must define a set of system colors. The JDatePicker suite components use such colors to initialize their color scheme and if these colors are not defined in the defaults table, a ColorUIResource NullPointerException is thrown.
The following lines show how such an exception might look:
Failed to register a UI delegate for null
java.lang.NullPointerException
at javax.swing.plaf.ColorUIResource.<init>(ColorUIResource.java:47)
at com.standbysoft.component.date.swing.plaf.basic.AbstractDatePickerUI.bt(Unknown Source)
at com.standbysoft.component.date.swing.plaf.basic.AbstractDatePickerUI.installDefaults(Unknown Source)
at com.standbysoft.component.date.swing.plaf.basic.AbstractDatePickerUI.installUI(Unknown Source)
at javax.swing.JComponent.setUI(JComponent.java:650)
at com.standbysoft.component.date.swing.JDateComponent.setUI(Unknown Source)
at com.standbysoft.component.date.swing.JDateComponent.updateUI(Unknown Source)
at com.standbysoft.component.date.swing.JDateEditComponent.<init>(Unknown Source)
at com.standbysoft.component.date.swing.JDateEditComponent.<init>(Unknown Source)
at com.standbysoft.component.date.swing.JDatePicker.<init>(Unknown Source)
at com.standbysoft.component.date.swing.JDatePicker.<init>(Unknown Source)
... The system colors we use for initialization are: "activeCaption", "activeCaptionText", "controlText", "controlShadow" and "window". If they are not defined then their value is null.
The following line of code shows how such a system color might be used. If the color is not defined in the defaults table, a NPE is thrown.
component.setForeground(new ColorUIResource(UIManager.getColor("controlText")));This line says that the component will be initialized with the color "controlText" which is retrieved by the UIManager from the current look and feel. This sample code is common for all Swing components. Here's what happens in ColorUIResource when a null color is passed:
public ColorUIResource(Color c) {
super(c.getRed(), c.getGreen(), c.getBlue());
}To fix the problem, you must register all these colors in the look and feel after it is actually registered. In this way, when your application starts and creates a component, it will be able to retrieve the "controlText" color.
try {
UIManager.installLookAndFeel("Kunststoff", "com.incors.plaf.kunststoff.KunststoffLookAndFeel");
UIManager.setLookAndFeel("com.incors.plaf.kunststoff.KunststoffLookAndFeel");
UIManager.put("controlText", Color.black);
} catch (Exception ex) {
}The Kunststoff LF does define the "controlText" color. The above example is just to show how you could use it with your custom LF that does not define the system colors.
The JDatePicker component can be integrated with the JGoodies Plastic LF only if it is recompiled to allow inheritance for the PlasticComboBoxUI class. It must be done only for JDatePicker and not the other components because it uses a modified JComboBox to look like a combo box.
Read this section for more information on how to integrate JDatePicker with custom look and feels.
Starting with version 2.0.2 of JGoodies Looks, PlasticComboBoxUI is no longer final and so you don't need to recompile the code anymore.