UIManager.setLookAndFeel [message #16654] |
Fri, 23 January 2004 17:54  |
Eclipse User |
|
|
|
Originally posted by: wade.eccentrichosting.net
Hi all;
I have constructed a frame with ve. When I change the UIManager in my
main() method it changes the L&F but when I add the same try statement
into initialize() it does not change the L&F. My problem is that I need
to be able to load getClass().getResource("") in order to load a theme
for my L&F. Of course I can not use getClass() from a static method
main. Has anyone else ran into this? Where are other people setting the
L&F of their applications? URL's and suggestions are very welcome! In
general I really don't think it is a good idea to be setting the
UIManager out of main anyways.
Cheers;
Wade
|
|
|
|
Re: UIManager.setLookAndFeel [message #16686 is a reply to message #16654] |
Sat, 24 January 2004 17:53  |
Eclipse User |
|
|
|
Hi Wade,
So is the L&F the same throughout the application, or does it actually vary for
each class so that for each GUI class there is a separate resource that is loaded
related to it ? Using the initialize() method and getClass().getResource("...");
seems to imply that you want it separately initialized for each GUI class,
however you're also talking about changing the UIManager which is the global one
so this means that each time a class is created it is going to switch the global
one which doesn't seem right.
If it's meant to be a global L&F change that affects the application then the
right thing to do seems to me to set it in the main that starts you app. You can
always hard-code the class name that the resource is loaded to in the static so
instead of
getClass().getResource("...")
just do
MyClass.getResource("...");
If you want the L&F to be used by the Visual Editor then you can visit the
preferences page for Java->Visual Editor and there is a list of the registered
L&F classes. You can add a new one there and enter a class name for the L&F,
however we have to be able to instantiate it with a null constructor. For things
that use themes requiring arguments the technique is to create your own class
that has a null constructor and does all the resource initialization itself, and
then use this in the VE preferences page as the default L&F. This is also used
by the "Run As=>Java Application" launcher that lets you test GUI classes without
needing a main.
If you're into building plugins you can get your own look and feel class listed
in the VE preferences page (so it can be selected as the new default without you
having to use the new button to add it) with the extension point
<extension point="org.eclipse.ve.internal.java.core.vce.lookandfeel">
<lookandfeel name="Plugin" class="com.mylookandfeel.MyLFClass"/>
</extension>
Best regards,
Joe Winchester
|
|
|
Re: UIManager.setLookAndFeel [message #579377 is a reply to message #16654] |
Fri, 23 January 2004 20:24  |
Eclipse User |
|
|
|
It seems a bit of a kludge, but something like this should work:
public static void main(String[] args) {
MyJFrame foo = new MyJFrame();
try {
UIManager.setLookAndFeel(foo.getClass().getResource("..."));
} catch (Exception e) {}
SwingUtilities.updateComponentTreeUI(foo);
foo.show();
}
Good luck,
- Jeff
Wade Arnold wrote:
> Hi all;
> I have constructed a frame with ve. When I change the UIManager in
> my main() method it changes the L&F but when I add the same try
> statement into initialize() it does not change the L&F. My problem is
> that I need to be able to load getClass().getResource("") in order to
> load a theme for my L&F. Of course I can not use getClass() from a
> static method main. Has anyone else ran into this? Where are other
> people setting the L&F of their applications? URL's and suggestions are
> very welcome! In general I really don't think it is a good idea to be
> setting the UIManager out of main anyways.
>
> Cheers;
> Wade
>
|
|
|
Re: UIManager.setLookAndFeel [message #579394 is a reply to message #16654] |
Sat, 24 January 2004 17:53  |
Eclipse User |
|
|
|
Hi Wade,
So is the L&F the same throughout the application, or does it actually vary for
each class so that for each GUI class there is a separate resource that is loaded
related to it ? Using the initialize() method and getClass().getResource("...");
seems to imply that you want it separately initialized for each GUI class,
however you're also talking about changing the UIManager which is the global one
so this means that each time a class is created it is going to switch the global
one which doesn't seem right.
If it's meant to be a global L&F change that affects the application then the
right thing to do seems to me to set it in the main that starts you app. You can
always hard-code the class name that the resource is loaded to in the static so
instead of
getClass().getResource("...")
just do
MyClass.getResource("...");
If you want the L&F to be used by the Visual Editor then you can visit the
preferences page for Java->Visual Editor and there is a list of the registered
L&F classes. You can add a new one there and enter a class name for the L&F,
however we have to be able to instantiate it with a null constructor. For things
that use themes requiring arguments the technique is to create your own class
that has a null constructor and does all the resource initialization itself, and
then use this in the VE preferences page as the default L&F. This is also used
by the "Run As=>Java Application" launcher that lets you test GUI classes without
needing a main.
If you're into building plugins you can get your own look and feel class listed
in the VE preferences page (so it can be selected as the new default without you
having to use the new button to add it) with the extension point
<extension point="org.eclipse.ve.internal.java.core.vce.lookandfeel">
<lookandfeel name="Plugin" class="com.mylookandfeel.MyLFClass"/>
</extension>
Best regards,
Joe Winchester
|
|
|
Powered by
FUDForum. Page generated in 0.03200 seconds