Solved

how to set font in my swing application?

Posted on 2001-08-24
6
534 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Accepted Solution

by:
Tom7 earned 30 total points
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now