Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

Font

Description

The java.awt.Font class is used to create Font objects to set the font for drawing text, labels, text fields, buttons, etc.

Generic Font Names

There are three logical/generic font names. Java will select a font in the system that matches the general characteristics of the logical font.

serifThis text is in a serif font. Often used for blocks of text (eg, Times).
sansserifThis text is in a SansSerif font. Often used for titles (eg, Arial or Helvetica).
monospacedThis text is in a Monospaced font, often used for computer text (eg, Courier).

You can also get a list of the system fonts on the host computer. See below.

Constructor

Font f = new Font(name, style, size);

String nameint styleint size
"serif"
"sansserif"
"monospaced"

or a system font.
Font.PLAIN
Font.BOLD
Font.ITALIC
Font.BOLD+Font.ITALIC
Integer point size -- typically in range 10-48.

Example

JButton b = new JButton("OK");
b.setFont(new Font("sansserif", Font.BOLD, 32));

Available system fonts

For maximum portability, use the generic font names, but you can use any font installed in the system. It is suggested to use a font family name, and create the font from that, but you can also use the fonts directly. You can get an array of all available font family names or all fonts.

// Font info is obtained from the current graphics environment.
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

//--- Get an array of font names (smaller than the number of fonts)
String[] fontNames = ge.getAvailableFontFamilyNames();

//--- Get an array of fonts.  It's preferable to use the names above.
Font[] allFonts = ge.getAllFonts();

Using Fonts for Graphics

Font f;
f = new Font(String name, int style, int size);	// creates a new font

name is "Serif", "SansSerif", or "Monospaced", or a font on the system. style is Font.PLAIN. Font.BOLD, Font.ITALIC, or Font.BOLD+Font.ITALIC. size is the point size, typically in the range 8-48.

Example

Font big = new Font("SansSerif", Font.Bold, 48);
. . .
g.setFont(big);
g.drawString("Greetings Earthling");

Unicode fonts

If you're running a recent version of Windows, you probably already have a Unicode font installed, Arial Unicode MS, which is a very extensive Unicode font. If you're not running windows, you can get a the Bitstream Cyberbit font, which is quite complete (about 30,000 characters), but lacks a few of the the lesser used characters (eg, Old Cyrillic).

Windows installation instructions:

  1. Download from ftp://ftp.netscape.com/pub/communicator/extras/fonts/windows/Cyberbit.ZIP [6.3MB Zipped]. It's also available other places on the Internet. It was originally written by Bitstream, but they no longer offer it for free download.
  2. Unzip into a temporary directory.
  3. Start the Fonts control panel, and add Bitstream Cyberbit font from that directory.

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.