File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set Global Font in Swing Application

 
Kasi Viswan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10974
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iterate the UIManager defaults, looking for fonts, and setting them to what you want
 
Kasi Viswan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic