Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using external fonts.

Status
Not open for further replies.

EugeneG

Technical User
Oct 2, 2001
7
US
This must be really simple, but I don't know how to do it. Laugh as long as you can ;-)
How do we specify custom font files to be used for output like drawString? g.SetFont doesn't seem to need the filename, then what does it need?
 
by custom I am assuming you mean just anything except for the default? Also I am not sure about your intended output format, however I can only tell you about screen components. Sorry.

You can either create creat a Font object specifying the font name size and effects such as bold or itlaic etc. This is recommended if you are going to need to reuse the font for several components.

e.g. Font myFont = new Font("Serif", BOLD, 24);

The just add this object to the component you want to change the font of by using the setFont method of the JComponent class.

e.g.

JLabel myLabel = new JLabel("FREDDY");
myLable.setFont(myFont);

or of course you can create the font object on the fly (better if you only need to use it in one or two places).

e.g.

myLabel.setFont(new Font("Serif", BOLD, 24));

blah blah blah

I hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top