File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using UIDefaults to configure L&F

 
Terence Doyle
Ranch Hand
Posts: 328
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic