Switch to full style
General Java code examples
Post a reply

Fonts in java

Tue Nov 11, 2008 7:40 pm

Fonts in java
Code:
import java.awt.*;
import javax.swing.*;

public class DisplayDifferentFonts extends JComponent {
   String[] differentFonts;
   Font[] font;
   static final int IN = 15;
   public DisplayDifferentFonts() {
   
   differentFonts 
= GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getAvailableFontFamilyNames();
    font = new Font[differentFonts.length];
  }
  public void paintComponent(Graphics g) {
    for (int j = 0; j < differentFonts.length; j += 1) {
      if (font[j] == null) {
        font[j] = new Font(differentFonts[j], Font.PLAIN, 16);
      }
      g.setFont(font[j]);
      int p = 15;
      int q = 15+ (IN * j);
      g.drawString(differentFonts[j],p,q);
    }
  }
  public static void main(String[] args) {
    JFrame frame = new JFrame("Different Fonts");
    frame.getContentPane().add(new JScrollPane(new DisplayDifferentFonts()));
    frame.setSize(350, 650);
    frame.setVisible(true);
  }
}
 



Attachments
differentFonts.gif
different fonts in java
differentFonts.gif (10.25 KiB) Viewed 17984 times

Post a reply
  Related Posts  to : Fonts in java
 Using two different fonts in the same webpage     -  
 Use TrueType Fonts in php     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 java or .net     -  
 need help in java     -  
 Using FTP in java     -  
 what is java     -  
 Java course     -  
 What is Java API?!!!     -  
 MS-Access with java     -  

Topic Tags

Java Graphics