Solved

how to set font in my swing application?

Posted on 2001-08-24
6
550 Views
Last Modified: 2013-12-03
Hi,

My swing application has a JFrame that contains many components(such as a menu, a tabbed pane...etc).
How can I set font for all these components? Do I have to use Java Look&Feel?
Thanks.


0
Comment
Question by:hairin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:Tom7
ID: 6426119
You can set the fonts for individual component classes. Here's an example:


Font f = new Font("helvetica", Font.BOLD, 14);
UIManager.put("Menu.font", f); // sets the default font for JMenu
UIManager.put("TabbedPane.font", f); // sets the default font for JTabbedPane
...
...

Tom
0
 

Author Comment

by:hairin
ID: 6427397
Thanks for your suggestion, Tom.
But is there a method to set font for all components instead of setting font everytime I add a new component?

0
 

Author Comment

by:hairin
ID: 6427430
Thanks for your suggestion, Tom.
But is there a method to set font for all components instead of setting font everytime I add a new component?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
Tom7 earned 30 total points
ID: 6428136
You have to set the font once for each type. If you put the line

UIManager.put("Menu.font", f); // sets the default font for JMenu

in your code ALL JMenus will have that font. (I'm not sure if this is what you meant).

I don't think there's an easy solution to change default fonts of all JComponent types!

Cheers Tom
0
 
LVL 5

Expert Comment

by:vemul
ID: 7773787
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- points to Tom7

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7861673
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question