aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Set Global Font in Swing Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Set Global Font in Swing Application" Watch "Set Global Font in Swing Application" New topic
Author

Set Global Font in Swing Application

Kasi Viswan
Ranch Hand

Joined: Sep 27, 2008
Posts: 42
Hi,

I am a swing newbie. I have some questions,
1. I would like to know is it possible to set font on JPanel and make the font applicable to all components on the JPanel like JTextBox, JLabel...
I tried setting font on individual components, it worked but when set on JPanel, it didn't work.

2. What is the most widely used font in Swing Applications when delivering the product to customers.

3. What would happen if we tried to set a font and that font is missing/not installed in the users computer, will that result in null pointer exceptions?

i appreciate your time and comments on these.

Thanks
Kasi
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8


1. I would like to know is it possible to set font on JPanel and make the font applicable to all components on the JPanel like JTextBox, JLabel...
I tried setting font on individual components, it worked but when set on JPanel, it didn't work.

2. What is the most widely used font in Swing Applications when delivering the product to customers.

3. What would happen if we tried to set a font and that font is missing/not installed in the users computer, will that result in null pointer exceptions?
[/QB]


1) JPanel is used as a container and as such does not have any text to display on its own. So setting the font for a JPanel doesn't have any effect. In case you are thinking, the font will be inherited by the children added to the panel, no it doesn't work that way

2) I usually set the LAF to the System LAF and don't worry about fonts at all. This is good usability. The user is presented with a UI with fonts and color schemes he is already used to.

3) Why don't you try it out yourself and let us know?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
iterate the UIManager defaults, looking for fonts, and setting them to what you want
Kasi Viswan
Ranch Hand

Joined: Sep 27, 2008
Posts: 42
Thanks Maneesh and Michael for your inputs, was helpful.

I want to set the font as Verdana, so i checked if Verdana is available in the system fonts, if yes, i will set that font otherwise will bypassing setting the custom font. It works.

Thanks Again,
Kasi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set Global Font in Swing Application