?
Solved

how to set font in my swing application?

Posted on 2001-08-24
6
Medium Priority
?
555 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

719 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