I'm creating a custom component with its own custom UI. The question How to create a custom Swing Component provided a great start in developing the component, but I haven't been able to find a good way to connect the custom component with its UI.
The code in How to Write a Custom Swing Component is good, but the implementation of JFlexiSlider.updateUI hard codes the UI to use BasicFlexiSliderUI:
public void updateUI() {
if (UIManager.get(getUIClassID()) != null) {
setUI((FlexiSliderUI) UIManager.getUI(this));
} else {
setUI(new BasicFlexiSliderUI());
}
}
The standard Swing components implement updateUI to simply set the UI directly from UIManager.get(this). The mapping from the UIClassID to the actual implementation is in BasicLookAndFeel and subclasses.
In my case, where I don't want to create a new look and feel, where would I set the default mapping from my UIClassID to the actual implementation? It seems like it should be outside the component class, but it needs to be added to the UIDefaults object prior to the first use of the custom component.