Solved

how to set font in my swing application?

Posted on 2001-08-24
6
538 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
expectj telnet failing 5 35
eclipse buid path vs tomcat lib path 10 22
maven module vs maven project 3 22
Is Applet the way to go for my drag and drop system? 8 10
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

776 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