aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Using UIDefaults to configure L&F Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using UIDefaults to configure L&F" Watch "Using UIDefaults to configure L&F" New topic
Author

Using UIDefaults to configure L&F

Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
I'm trying to give a few Font & Color options to users of an application and I thought changing the UIDefaults contents might work.


And it does, to some extent. If I replace a property for say the ToolTip.background while the application is running it works fine. As does changing the Table.selectionBackground.
But changing the Label.font does not change the Labels already painted.
I presume this is because the tooltip and table selection properties are created "on-the-fly" from the UIDefaults for each new event. The Label however doesn't change because no event has caused it to recreate itself. (I've tried using repaint() and revalidate() but no luck ).
Has anyone found a way around this?
Thanks,
Terry
NEP - edited post to make long code line wrap.
[ January 15, 2002: Message edited by: Nathan Pruett ]

Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
you are right Terry, we just cant change on the fly , but I tried creating a new UIResource object for Font & set it explicitly to the components whose Label's font I wanted to change, it worked then. Heres the code, I hope this solves ur problem:
FontUIResource fontChange = new FontUIResource(new Font("MS Sans Serif",Font.ITALIC,11));
uid.put("ToolTip.font",fontChange);
& then :
//some button creation code ...
if ((button.getFont() instanceof UIResource))
{
button.setFont(UIManager.getFont("ToolTip.font"));//this works!
}
I guess components have the ComponentUI classes's methods called when they are painted ,so thats y it gets the DefaultUI , in this case for a button.
Vinod


- Vinod<br />-------<br />SCJP2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using UIDefaults to configure L&F