Why can’t I load properties using UIDefaults?
You may encounter this problem while porting a Swing application to the NetBeans platform or when using a third-party library like SwingX. While the following code works in a standalone Swing application, it does not load the property in a platform-based application:
UIManager.getDefaults().addResourceBundle("com.example.foo.sample");
myLabel.setText(UIManager.getString("greeting"));
This fails in the platform because of JDK bug #4834404. Although the best solution is to replace the original code to load properties in a way that uses the correct class loader, that may not be possible when using a third-party library. In these cases, your module can work around the problem by using code similar to this:
UIDefaults def = UIManager.getDefaults();
ResourceBundle bundle = ResourceBundle.getBundle("com.example.foo.sample");
Enumeration<String> e = bundle.getKeys();
while (e.hasMoreElements()) {
String key = e.nextElement();
def.put(key, bundle.getString(key));
}
Yet another alternative is to ensure the resource bundles are available to the startup classloader.
You can do this by placing the JAR containing the resource bundles
in the lib
subdirectory of your platform
cluster,
although this workaround has not been tested.
Note: An (untested) possible workaround is to first call UIManager.put ("ClassLoader", Lookup.getDefault().lookup(ClassLoader.class)).
Applies to: NetBeans 6.8 and above