I'm trying to add a plugin system where people can install their own custom looks and feels. I'm not sure how I'd actually install it so it could be found by going through UIManager.getInstalledLookAndFeels()?
I've tried this:
public static void registerPlugins()
{
File[] files = pluginDir.listFiles();
for(int i = 0; i < files.length; i++)
{
if(files[i].getName().endsWith(".config"))
{
System.out.println("Found plugin");
File jarfile = new File(pluginDir,files[i].getName().substring(0,files[i].getName().length()-7)+".jar");
if(jarfile.exists())
{
System.out.println("Found jar");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(files[i]));
String name = reader.readLine(); //Unused for now
String classname = reader.readLine();
reader.close();
reader = null;
URL url = jarfile.toURI().toURL();
URL[] urls = new URL[]{url};
ClassLoader cl = new URLClassLoader(urls);
Class<?> lafClass = cl.loadClass(classname);
final LookAndFeel laf = (LookAndFeel)lafClass.newInstance();
UIManager.getLookAndFeelDefaults().put("ClassLoader", cl);
UIManager.installLookAndFeel(laf.getName(), laf.getClass().getName());
} catch (Exception e) {
try {
if(reader != null)
reader.close();
} catch (Exception es) {
// TODO Auto-generated catch block
e.printStackTrace();
}
e.printStackTrace();
}
}
}
}
}
This gets the config files from the plugins folder that have contents like Web look and feel com.alee.laf.WebLookAndFeel and loads the respective jar. So far, all it did was crash cause it could not load components, or list the look and feel while also not being able to find it, so like the list SHOWS "WebLookAndFeel" but trying to use com.alee.laf.WebLookAndFeel causes an exception.
Any advice?