| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = DevFaqUiDefaultsPropsNotFound |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| |
| === 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: |
| |
| [source,java] |
| ---- |
| |
| UIManager.getDefaults().addResourceBundle("com.example.foo.sample"); |
| myLabel.setText(UIManager.getString("greeting")); |
| ---- |
| |
| This fails in the platform because of link:http://bugs.sun.com/view_bug.do?bug_id=4834404[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: |
| |
| [source,java] |
| ---- |
| |
| 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)). |
| |
| <hr/> |
| Applies to: NetBeans 6.8 and above |
| |
| === Apache Migration Information |
| |
| The content in this page was kindly donated by Oracle Corp. to the |
| Apache Software Foundation. |
| |
| This page was exported from link:http://wiki.netbeans.org/DevFaqUiDefaultsPropsNotFound[http://wiki.netbeans.org/DevFaqUiDefaultsPropsNotFound] , |
| that was last modified by NetBeans user Jpirek |
| on 2011-11-28T08:19:13Z. |
| |
| |
| *NOTE:* This document was automatically converted to the AsciiDoc format on 2018-01-10, and needs to be reviewed. |