Re: Dynamically load laf
- From: Daniel <daik.no-spam@xxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Nov 2005 01:34:04 GMT
>You realise you have to put the jars file names in the classpath, not
>just the directory they are in. I seem to remember a feature in 1.6 for
>allowing specifying the directory only, but don't quote me on that.
yes, I have realized that, and that is basically the root of the
problem here.
>URLClassLoader should do just as well. I'm not certain what your problem
>with the classpath was, but it is probably worthwhile sorting that one
>out first.
yeah, I have realized that, and scrapped my own classloader.
>Perhaps it might help if we saw the code of how you are attempting to
>use the class loader to install the PL&F.
Currently I am doing this:
if(dir.exists()){
ClassLoader loader= ClassLoader.getSystemClassLoader();
java.net.URLClassLoader ul=null;
if(loader instanceof java.net.URLClassLoader){
ul=(java.net.URLClassLoader)loader;
}
File[] lafs= dir.listFiles();
int jarnum=0;
for(int i=0;i<lafs.length;i++){
if (lafs[i].getName().endsWith(".jar")) {
jarnum++;
}
}
java.net.URL[] url= new java.net.URL[jarnum];
int j=0;
for(int i=0;i<lafs.length;i++){
if(lafs[i].getName().endsWith(".jar")){
int ind=lafs[i].getName().lastIndexOf(".jar");
url[j]= lafs[i].toURL();
ul= new java.net.URLClassLoader(url);
j++;
Class c=ul.loadClass(lafs[i].getName().substring(0,ind));
UIManager.setLookAndFeel((javax.swing.LookAndFeel)c.newInstance());
}
}
from what I understand the line ul= new URL.... is actually quite
stupid, since I basically just change the local variable and not the
instance being used at other places. Ideally I would just add the new
url to the existing one, but as I said it is not possible.
Some of this code is not very good, but I will clean it up and make it
smarter and better when I understand what I am doing :)
>You want to do all this for every class loaded? For one thing, you are
>not closing your input streams, even in the normal case. Using a ZipFile
>would probably be better, too.
actually this is pretty much a work in progress, once I got it working
I would clean it up, and look at things like what you mention here.
The same with the code pasted above. I want to solve the problem
first, only then can I begin to optemize away things not needed, or
done in a stupid way.
.
- References:
- Dynamically load laf
- From: Daniel
- Re: Dynamically load laf
- From: Thomas Hawtin
- Dynamically load laf
- Prev by Date: Re: Dynamically load laf
- Next by Date: Re: menonic without alt key (or similar)
- Previous by thread: Re: Dynamically load laf
- Next by thread: Java 1.5 and system fonts
- Index(es):
Relevant Pages
|
|