/** * Call the LookAndFeelFactory.installJideExtension using a specific class loader. This is used for GUI context * switch when going between two class loaders. * * @param newLoader ClassLoader */ public static void installJideExtension(ClassLoader newLoader) { installJideExtension(newLoader, false); }
public static void reinstallJideExtension() { installJideExtension(currentLoader, true); }
@Override public ComponentUI getUI(JComponent target) { UIDefaults defaults = UIManager.getDefaults(); // to increase the performance, UIManager is caching the // className <--> class definition object // It does not differentiate between classNames from different class loaders // This means that the cached class definition may not match the current // classloader and will cause ClassCastException later on. // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4675772 String className = (String) defaults.get(target.getUIClassID()); Class componentUIClass = className != null ? (Class) defaults.get(className) : null; ClassLoader componentUIClassLoader = componentUIClass != null ? componentUIClass.getClassLoader() : null; ClassLoader targetClassLoader = target.getClass().getClassLoader(); ClassLoader uiClassLoader = (ClassLoader) UIManager.get("ClassLoader"); if (targetClassLoader == null) { // for JMenuItem and JPopupMenu.Separator if (componentUIClassLoader != null && componentUIClassLoader != uiClassLoader) { removeCachedClass(defaults, componentUIClass); } return null; } if (targetClassLoader != componentUIClassLoader || targetClassLoader != uiClassLoader) { if (componentUIClassLoader != null) { removeCachedClass(defaults, componentUIClass); } installJideExtension(targetClassLoader); } return null; } }