Tue Nov 11, 2008 7:40 pm
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);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.