Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to set font in my swing application?

Posted on 2001-08-24
6
Medium Priority
?
557 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
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
Technology Partners: 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 120 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

Industry Leaders: 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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

927 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